From a626887c7ba27423e233b80aa394138946242d5d Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 14:37:47 +0100 Subject: [PATCH 01/34] Fix #262: Moved from Newtonsoft.Json to System.Text.Json --- CDP4-SDK.sln | 6 + CDP4-SDK.sln.DotSettings | 2 +- CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs | 38 +- .../OperationContainerTestFixture.cs | 38 +- .../Operations/OperationTestFixture.cs | 30 +- .../Operations/PostOperationTestFixture.cs | 40 +- .../Operations/ThingTransactionTestFixture.cs | 39 +- CDP4Dal.NetCore.Tests/SessionTestFixture.cs | 129 +- CDP4Dal.Tests/DAL/DalTestFixture.cs | 61 +- .../OperationContainerTestFixture.cs | 38 +- .../Operations/OperationTestFixture.cs | 30 +- .../Operations/PostOperationTestFixture.cs | 40 +- .../Operations/ThingTransactionTestFixture.cs | 84 +- CDP4Dal.Tests/SessionTestFixture.cs | 107 +- CDP4Dal/DAL/Dal.cs | 39 +- CDP4Dal/DAL/IDal.cs | 35 +- .../InvalidOperationContainerException.cs | 22 +- .../InvalidOperationKindException.cs | 24 +- CDP4Dal/ISession.cs | 22 +- CDP4Dal/Operations/IThingTransaction.cs | 29 +- CDP4Dal/Operations/LongRunningTaskResult.cs | 4 +- CDP4Dal/Operations/OperationContainer.cs | 37 +- CDP4Dal/Operations/OperationKindExtensions.cs | 26 +- CDP4Dal/Operations/ThingTransaction.cs | 135 +- CDP4Dal/Session.cs | 23 +- .../Protocol}/Operations/Operation.cs | 136 +- .../Protocol}/Operations/OperationKind.cs | 180 +- .../Protocol}/Operations/PostOperation.cs | 157 +- .../{ => Protocol}/Tasks/CometTask.cs | 10 +- .../{ => Protocol}/Tasks/StatusKind.cs | 25 +- .../CDP4DalJsonSerializer.csproj | 44 + .../Cdp4DalJsonSerializer.cs | 86 + .../Extensions/JsonElementExtensions.cs | 70 + .../PostOperationJsonConverter.cs | 150 ++ .../JsonFileDalTestFixture.cs | 19 +- .../JsonFileDalTestFixture.cs | 27 +- CDP4JsonFileDal/CDP4JsonFileDal.csproj | 1 + CDP4JsonFileDal/JsonFileDal.cs | 39 +- .../Helper/SerializerHelperTestFixture.cs | 46 +- .../JsonSerializerTestFixture.cs | 29 +- .../Helper/SerializerHelperTestFixture.cs | 48 +- .../JsonSerializerTestFixture.cs | 34 +- .../PostOperation/CdpPostOperation.cs | 29 +- .../ActionItemResolver.cs | 292 ++- .../ActualFiniteStateListResolver.cs | 132 +- .../ActualFiniteStateResolver.cs | 121 +- .../AutoGenDtoDeserializer/AliasResolver.cs | 136 +- .../AndExpressionResolver.cs | 110 +- .../ApprovalResolver.cs | 169 +- .../ArrayParameterTypeResolver.cs | 205 ++- .../BinaryNoteResolver.cs | 176 +- .../BinaryRelationshipResolver.cs | 161 +- .../BinaryRelationshipRuleResolver.cs | 216 ++- .../AutoGenDtoDeserializer/BookResolver.cs | 158 +- .../BooleanParameterTypeResolver.cs | 175 +- .../AutoGenDtoDeserializer/BoundsResolver.cs | 158 +- .../BuiltInRuleVerificationResolver.cs | 148 +- .../CategoryResolver.cs | 182 +- .../ChangeProposalResolver.cs | 259 ++- .../ChangeRequestResolver.cs | 248 ++- .../CitationResolver.cs | 158 +- .../AutoGenDtoDeserializer/ColorResolver.cs | 147 +- .../CommonFileStoreResolver.cs | 150 +- .../CompoundParameterTypeResolver.cs | 190 +- .../ConstantResolver.cs | 191 +- .../ContractChangeNoticeResolver.cs | 259 ++- .../CyclicRatioScaleResolver.cs | 270 ++- .../DateParameterTypeResolver.cs | 175 +- .../DateTimeParameterTypeResolver.cs | 175 +- .../DecompositionRuleResolver.cs | 197 +- .../DefinitionResolver.cs | 140 +- ...ependentParameterTypeAssignmentResolver.cs | 125 +- .../DerivedQuantityKindResolver.cs | 208 ++- .../DerivedUnitResolver.cs | 161 +- .../DiagramCanvasResolver.cs | 139 +- .../DiagramEdgeResolver.cs | 183 +- .../DiagramObjectResolver.cs | 179 +- .../DomainFileStoreResolver.cs | 161 +- .../DomainOfExpertiseGroupResolver.cs | 164 +- .../DomainOfExpertiseResolver.cs | 164 +- .../AutoGenDtoDeserializer/DtoFactory.cs | 34 +- .../ElementDefinitionResolver.cs | 199 +- .../ElementUsageResolver.cs | 200 +- .../EmailAddressResolver.cs | 125 +- ...ineeringModelDataDiscussionItemResolver.cs | 158 +- .../EngineeringModelDataNoteResolver.cs | 172 +- .../EngineeringModelResolver.cs | 164 +- .../EngineeringModelSetupResolver.cs | 236 ++- .../EnumerationParameterTypeResolver.cs | 190 +- .../EnumerationValueDefinitionResolver.cs | 146 +- .../ExclusiveOrExpressionResolver.cs | 110 +- .../ExternalIdentifierMapResolver.cs | 176 +- .../AutoGenDtoDeserializer/FileResolver.cs | 139 +- .../FileRevisionResolver.cs | 162 +- .../FileTypeResolver.cs | 175 +- .../AutoGenDtoDeserializer/FolderResolver.cs | 158 +- .../GlossaryResolver.cs | 171 +- .../AutoGenDtoDeserializer/GoalResolver.cs | 153 +- .../HyperLinkResolver.cs | 136 +- .../IdCorrespondenceResolver.cs | 125 +- ...ependentParameterTypeAssignmentResolver.cs | 125 +- .../IntervalScaleResolver.cs | 259 ++- .../IterationResolver.cs | 263 ++- .../IterationSetupResolver.cs | 180 +- .../LinearConversionUnitResolver.cs | 179 +- .../LogEntryChangelogItemResolver.cs | 143 +- .../LogarithmicScaleResolver.cs | 310 +++- .../MappingToReferenceScaleResolver.cs | 125 +- .../ModelLogEntryResolver.cs | 186 +- .../ModelReferenceDataLibraryResolver.cs | 238 ++- .../ModellingThingReferenceResolver.cs | 125 +- .../MultiRelationshipResolver.cs | 146 +- .../MultiRelationshipRuleResolver.cs | 197 +- .../NaturalLanguageResolver.cs | 136 +- .../NestedElementResolver.cs | 136 +- .../NestedParameterResolver.cs | 169 +- .../NotExpressionResolver.cs | 114 +- .../AutoGenDtoDeserializer/OptionResolver.cs | 160 +- .../OrExpressionResolver.cs | 110 +- .../OrdinalScaleResolver.cs | 270 ++- .../OrganizationResolver.cs | 136 +- .../OrganizationalParticipantResolver.cs | 114 +- .../OwnedStyleResolver.cs | 253 ++- .../AutoGenDtoDeserializer/PageResolver.cs | 158 +- .../ParameterGroupResolver.cs | 125 +- .../ParameterOverrideResolver.cs | 139 +- .../ParameterOverrideValueSetResolver.cs | 149 +- .../ParameterResolver.cs | 216 ++- .../ParameterSubscriptionResolver.cs | 121 +- .../ParameterSubscriptionValueSetResolver.cs | 130 +- .../ParameterTypeComponentResolver.cs | 136 +- .../ParameterValueSetResolver.cs | 161 +- .../ParameterizedCategoryRuleResolver.cs | 175 +- .../ParametricConstraintResolver.cs | 121 +- .../ParticipantPermissionResolver.cs | 136 +- .../ParticipantResolver.cs | 154 +- .../ParticipantRoleResolver.cs | 164 +- .../PersonPermissionResolver.cs | 136 +- .../AutoGenDtoDeserializer/PersonResolver.cs | 256 ++- .../PersonRoleResolver.cs | 164 +- .../AutoGenDtoDeserializer/PointResolver.cs | 136 +- .../PossibleFiniteStateListResolver.cs | 179 +- .../PossibleFiniteStateResolver.cs | 146 +- .../PrefixedUnitResolver.cs | 157 +- .../PublicationResolver.cs | 128 +- .../QuantityKindFactorResolver.cs | 125 +- .../RatioScaleResolver.cs | 259 ++- .../ReferenceSourceResolver.cs | 241 ++- .../ReferencerRuleResolver.cs | 197 +- .../RelationalExpressionResolver.cs | 141 +- .../RelationshipParameterValueResolver.cs | 130 +- .../RequestForDeviationResolver.cs | 248 ++- .../RequestForWaiverResolver.cs | 248 ++- .../RequirementResolver.cs | 197 +- ...irementsContainerParameterValueResolver.cs | 130 +- .../RequirementsGroupResolver.cs | 178 +- .../RequirementsSpecificationResolver.cs | 196 +- .../ReviewItemDiscrepancyResolver.cs | 255 ++- .../RuleVerificationListResolver.cs | 161 +- .../RuleViolationResolver.cs | 121 +- .../SampledFunctionParameterTypeResolver.cs | 199 +- .../ScaleReferenceQuantityValueResolver.cs | 125 +- .../ScaleValueDefinitionResolver.cs | 157 +- .../AutoGenDtoDeserializer/SectionResolver.cs | 158 +- .../SharedStyleResolver.cs | 253 ++- .../SimpleParameterValueResolver.cs | 130 +- .../SimpleQuantityKindResolver.cs | 204 ++- .../SimpleUnitResolver.cs | 157 +- .../SiteDirectoryDataAnnotationResolver.cs | 172 +- ...SiteDirectoryDataDiscussionItemResolver.cs | 158 +- .../SiteDirectoryResolver.cs | 246 ++- .../SiteDirectoryThingReferenceResolver.cs | 125 +- .../SiteLogEntryResolver.cs | 186 +- .../SiteReferenceDataLibraryResolver.cs | 249 ++- .../SolutionResolver.cs | 158 +- .../SpecializedQuantityKindResolver.cs | 215 ++- .../StakeHolderValueMapResolver.cs | 188 +- .../StakeHolderValueMapSettingsResolver.cs | 136 +- .../StakeholderResolver.cs | 160 +- .../StakeholderValueResolver.cs | 153 +- .../TelephoneNumberResolver.cs | 121 +- .../AutoGenDtoDeserializer/TermResolver.cs | 157 +- .../TextParameterTypeResolver.cs | 175 +- .../TextualNoteResolver.cs | 176 +- .../TimeOfDayParameterTypeResolver.cs | 175 +- .../UnitFactorResolver.cs | 125 +- .../UnitPrefixResolver.cs | 168 +- .../UserPreferenceResolver.cs | 125 +- .../UserRuleVerificationResolver.cs | 148 +- .../ValueGroupResolver.cs | 153 +- .../ActionItemSerializer.cs | 1180 +++++++++++- .../ActualFiniteStateListSerializer.cs | 637 ++++++- .../ActualFiniteStateSerializer.cs | 517 +++++- .../AutoGenDtoSerializer/AliasSerializer.cs | 529 +++++- .../AndExpressionSerializer.cs | 481 ++++- .../ApprovalSerializer.cs | 607 +++++- .../ArrayParameterTypeSerializer.cs | 997 +++++++++- .../BinaryNoteSerializer.cs | 658 ++++++- .../BinaryRelationshipRuleSerializer.cs | 889 ++++++++- .../BinaryRelationshipSerializer.cs | 670 ++++++- .../AutoGenDtoSerializer/BookSerializer.cs | 643 ++++++- .../BooleanParameterTypeSerializer.cs | 805 +++++++- .../AutoGenDtoSerializer/BoundsSerializer.cs | 574 +++++- .../BuiltInRuleVerificationSerializer.cs | 660 ++++++- .../CategorySerializer.cs | 865 ++++++++- .../ChangeProposalSerializer.cs | 1054 ++++++++++- .../ChangeRequestSerializer.cs | 1021 ++++++++++- .../CitationSerializer.cs | 601 +++++- .../AutoGenDtoSerializer/ColorSerializer.cs | 565 +++++- .../CommonFileStoreSerializer.cs | 649 ++++++- .../CompoundParameterTypeSerializer.cs | 901 ++++++++- .../ConstantSerializer.cs | 899 ++++++++- .../ContractChangeNoticeSerializer.cs | 1054 ++++++++++- .../CyclicRatioScaleSerializer.cs | 1153 +++++++++++- .../DateParameterTypeSerializer.cs | 805 +++++++- .../DateTimeParameterTypeSerializer.cs | 805 +++++++- .../DecompositionRuleSerializer.cs | 913 ++++++++- .../DefinitionSerializer.cs | 673 ++++++- ...endentParameterTypeAssignmentSerializer.cs | 457 ++++- .../DerivedQuantityKindSerializer.cs | 997 +++++++++- .../DerivedUnitSerializer.cs | 769 +++++++- .../DiagramCanvasSerializer.cs | 577 +++++- .../DiagramEdgeSerializer.cs | 832 ++++++++- .../DiagramObjectSerializer.cs | 781 +++++++- .../DomainFileStoreSerializer.cs | 685 ++++++- .../DomainOfExpertiseGroupSerializer.cs | 769 +++++++- .../DomainOfExpertiseSerializer.cs | 769 +++++++- .../ElementDefinitionSerializer.cs | 1051 ++++++++++- .../ElementUsageSerializer.cs | 961 +++++++++- .../EmailAddressSerializer.cs | 493 ++++- ...eeringModelDataDiscussionItemSerializer.cs | 601 +++++- .../EngineeringModelDataNoteSerializer.cs | 703 ++++++- .../EngineeringModelSerializer.cs | 826 ++++++++- .../EngineeringModelSetupSerializer.cs | 1183 +++++++++++- .../EnumerationParameterTypeSerializer.cs | 901 ++++++++- .../EnumerationValueDefinitionSerializer.cs | 673 ++++++- .../ExclusiveOrExpressionSerializer.cs | 481 ++++- .../ExternalIdentifierMapSerializer.cs | 733 +++++++- .../FileRevisionSerializer.cs | 697 ++++++- .../AutoGenDtoSerializer/FileSerializer.cs | 649 ++++++- .../FileTypeSerializer.cs | 805 +++++++- .../AutoGenDtoSerializer/FolderSerializer.cs | 637 ++++++- .../GlossarySerializer.cs | 829 ++++++++- .../AutoGenDtoSerializer/GoalSerializer.cs | 679 ++++++- .../HyperLinkSerializer.cs | 529 +++++- .../IdCorrespondenceSerializer.cs | 493 ++++- ...endentParameterTypeAssignmentSerializer.cs | 457 ++++- .../IntervalScaleSerializer.cs | 1117 ++++++++++- .../IterationSerializer.cs | 1630 +++++++++++++++-- .../IterationSetupSerializer.cs | 745 +++++++- .../LinearConversionUnitSerializer.cs | 781 +++++++- .../LogEntryChangelogItemSerializer.cs | 511 +++++- .../LogarithmicScaleSerializer.cs | 1321 +++++++++++-- .../MappingToReferenceScaleSerializer.cs | 493 ++++- .../ModelLogEntrySerializer.cs | 859 ++++++++- .../ModelReferenceDataLibrarySerializer.cs | 1465 ++++++++++++++- .../ModellingThingReferenceSerializer.cs | 475 ++++- .../MultiRelationshipRuleSerializer.cs | 877 ++++++++- .../MultiRelationshipSerializer.cs | 658 ++++++- .../NaturalLanguageSerializer.cs | 529 +++++- .../NestedElementSerializer.cs | 613 ++++++- .../NestedParameterSerializer.cs | 673 ++++++- .../NotExpressionSerializer.cs | 457 ++++- .../AutoGenDtoSerializer/OptionSerializer.cs | 793 +++++++- .../OrExpressionSerializer.cs | 481 ++++- .../OrdinalScaleSerializer.cs | 1153 +++++++++++- .../OrganizationSerializer.cs | 529 +++++- .../OrganizationalParticipantSerializer.cs | 409 ++++- .../OwnedStyleSerializer.cs | 1186 +++++++++++- .../AutoGenDtoSerializer/PageSerializer.cs | 643 ++++++- .../ParameterGroupSerializer.cs | 529 +++++- .../ParameterOverrideSerializer.cs | 613 ++++++- .../ParameterOverrideValueSetSerializer.cs | 603 +++++- .../ParameterSerializer.cs | 1009 +++++++++- .../ParameterSubscriptionSerializer.cs | 517 +++++- ...ParameterSubscriptionValueSetSerializer.cs | 515 +++++- .../ParameterTypeComponentSerializer.cs | 565 +++++- .../ParameterValueSetSerializer.cs | 711 ++++++- .../ParameterizedCategoryRuleSerializer.cs | 805 +++++++- .../ParametricConstraintSerializer.cs | 553 +++++- .../ParticipantPermissionSerializer.cs | 529 +++++- .../ParticipantRoleSerializer.cs | 769 +++++++- .../ParticipantSerializer.cs | 625 ++++++- .../PersonPermissionSerializer.cs | 529 +++++- .../PersonRoleSerializer.cs | 769 +++++++- .../AutoGenDtoSerializer/PersonSerializer.cs | 1213 +++++++++++- .../AutoGenDtoSerializer/PointSerializer.cs | 508 ++++- .../PossibleFiniteStateListSerializer.cs | 901 ++++++++- .../PossibleFiniteStateSerializer.cs | 673 ++++++- .../PrefixedUnitSerializer.cs | 709 ++++++- .../PublicationSerializer.cs | 577 +++++- .../QuantityKindFactorSerializer.cs | 493 ++++- .../RatioScaleSerializer.cs | 1117 ++++++++++- .../ReferenceSourceSerializer.cs | 1165 +++++++++++- .../ReferencerRuleSerializer.cs | 877 ++++++++- .../RelationalExpressionSerializer.cs | 587 +++++- .../RelationshipParameterValueSerializer.cs | 522 +++++- .../RequestForDeviationSerializer.cs | 1021 ++++++++++- .../RequestForWaiverSerializer.cs | 1021 ++++++++++- .../RequirementSerializer.cs | 997 +++++++++- ...ementsContainerParameterValueSerializer.cs | 522 +++++- .../RequirementsGroupSerializer.cs | 871 ++++++++- .../RequirementsSpecificationSerializer.cs | 967 +++++++++- .../ReviewItemDiscrepancySerializer.cs | 1072 ++++++++++- .../RuleVerificationListSerializer.cs | 769 +++++++- .../RuleViolationSerializer.cs | 517 +++++- .../SampledFunctionParameterTypeSerializer.cs | 817 ++++++++- .../ScaleReferenceQuantityValueSerializer.cs | 493 ++++- .../ScaleValueDefinitionSerializer.cs | 709 ++++++- .../AutoGenDtoSerializer/SectionSerializer.cs | 643 ++++++- .../SerializerProvider.cs | 70 +- .../SharedStyleSerializer.cs | 1186 +++++++++++- .../SimpleParameterValueSerializer.cs | 551 +++++- .../SimpleQuantityKindSerializer.cs | 937 +++++++++- .../SimpleUnitSerializer.cs | 709 ++++++- .../SiteDirectoryDataAnnotationSerializer.cs | 676 ++++++- ...teDirectoryDataDiscussionItemSerializer.cs | 601 +++++- .../SiteDirectorySerializer.cs | 1360 +++++++++++++- .../SiteDirectoryThingReferenceSerializer.cs | 475 ++++- .../SiteLogEntrySerializer.cs | 859 ++++++++- .../SiteReferenceDataLibrarySerializer.cs | 1501 ++++++++++++++- .../SolutionSerializer.cs | 574 +++++- .../SpecializedQuantityKindSerializer.cs | 973 +++++++++- .../StakeHolderValueMapSerializer.cs | 934 +++++++++- .../StakeHolderValueMapSettingsSerializer.cs | 589 +++++- .../StakeholderSerializer.cs | 730 +++++++- .../StakeholderValueSerializer.cs | 679 ++++++- .../TelephoneNumberSerializer.cs | 517 +++++- .../AutoGenDtoSerializer/TermSerializer.cs | 709 ++++++- .../TextParameterTypeSerializer.cs | 805 +++++++- .../TextualNoteSerializer.cs | 658 ++++++- .../TimeOfDayParameterTypeSerializer.cs | 805 +++++++- .../UnitFactorSerializer.cs | 493 ++++- .../UnitPrefixSerializer.cs | 745 +++++++- .../UserPreferenceSerializer.cs | 493 ++++- .../UserRuleVerificationSerializer.cs | 660 ++++++- .../ValueGroupSerializer.cs | 679 ++++++- .../ActualFiniteStateKindDeserializer.cs | 64 + .../AnnotationApprovalKindDeserializer.cs | 65 + ...nnotationClassificationKindDeserializer.cs | 64 + .../AnnotationStatusKindDeserializer.cs | 68 + .../BooleanOperatorKindDeserializer.cs | 65 + .../ClassKindDeserializer.cs | 243 +++ .../EngineeringModelKindDeserializer.cs | 66 + .../InterfaceEndKindDeserializer.cs | 67 + .../LogEntryChangelogItemKindDeserializer.cs | 65 + .../LogLevelKindDeserializer.cs | 66 + .../LogarithmBaseKindDeserializer.cs | 65 + .../NumberSetKindDeserializer.cs | 66 + .../ParameterSwitchKindDeserializer.cs | 65 + .../ParticipantAccessRightKindDeserializer.cs | 69 + .../PersonAccessRightKindDeserializer.cs | 71 + .../RelationalOperatorKindDeserializer.cs | 68 + .../RuleVerificationStatusKindDeserializer.cs | 66 + .../StudyPhaseKindDeserializer.cs | 66 + .../VcardEmailAddressKindDeserializer.cs | 64 + .../VcardTelephoneNumberKindDeserializer.cs | 71 + CDP4JsonSerializer/CDP4JsonSerializer.csproj | 22 +- CDP4JsonSerializer/Cdp4JsonSerializer.cs | 178 +- .../DtoSerializer/BaseThingSerializer.cs | 40 +- .../DtoSerializer/IThingSerializer.cs | 51 +- CDP4JsonSerializer/Helper/SerializerHelper.cs | 130 +- CDP4JsonSerializer/ICdp4JsonSerializer.cs | 45 +- .../JsonConverter/ClassKindConverter.cs | 50 - .../JsonConverter/ClasslessDtoSerializer.cs | 174 +- .../JsonConverter/ThingConverterExtensions.cs | 111 ++ .../JsonConverter/ThingSerializer.cs | 157 +- CDP4JsonSerializer/Properties/AssemblyInfo.cs | 5 +- CDP4JsonSerializer/SerializerOptions.cs | 88 + .../CDP4ServicesDal.NetCore.Tests.csproj | 3 +- .../CdpServicesDalTestFixture.cs | 52 +- .../CopyOperationHandlerTestFixture.cs | 10 +- .../OperationModifierTestFixture.cs | 10 +- .../PostOperationTestFixture.cs | 47 +- .../CdpServicesDalTestFixture.cs | 51 +- .../CopyOperationHandlerTestFixture.cs | 10 +- .../OperationModifierTestFixture.cs | 12 +- .../PostOperationTestFixture.cs | 50 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 7 +- CDP4ServicesDal/CdpPostOperation.cs | 47 +- CDP4ServicesDal/CdpServicesDal.cs | 45 +- CDP4ServicesDal/CopyOperationHandler.cs | 41 +- CDP4ServicesDal/OperationModifier.cs | 49 +- CDP4ServicesDal/ValueSetOperationCreator.cs | 43 +- .../CDP4ServicesMessaging.csproj | 2 +- .../Serializers/Json/Cdp4MessageSerializer.cs | 38 +- .../CopyOperationHandlerTestFixture.cs | 10 +- .../OperationModifierTestFixture.cs | 10 +- .../Operations/WSPPostOperationTestFixture.cs | 36 +- .../PostOperationTestFixture.cs | 67 +- CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs | 10 +- .../CopyOperationHandlerTestFixture.cs | 10 +- .../OperationModifierTestFixture.cs | 12 +- .../Operations/WSPPostOperationTestFixture.cs | 36 +- CDP4WspDal.Tests/PostOperationTestFixture.cs | 66 +- CDP4WspDal.Tests/WSPDalTestFixture.cs | 10 +- CDP4WspDal/CDP4WspDal.csproj | 2 +- CDP4WspDal/CopyOperationHandler.cs | 51 +- CDP4WspDal/OperationModifier.cs | 53 +- CDP4WspDal/ValueSetOperationCreator.cs | 49 +- CDP4WspDal/WSPDal.cs | 64 +- CDP4WspDal/WSPPostOperation.cs | 45 +- 402 files changed, 120489 insertions(+), 20963 deletions(-) rename {CDP4Dal => CDP4DalCommon/Protocol}/Operations/Operation.cs (79%) rename {CDP4Dal => CDP4DalCommon/Protocol}/Operations/OperationKind.cs (84%) rename {CDP4Dal => CDP4DalCommon/Protocol}/Operations/PostOperation.cs (80%) rename CDP4DalCommon/{ => Protocol}/Tasks/CometTask.cs (92%) rename CDP4DalCommon/{ => Protocol}/Tasks/StatusKind.cs (57%) create mode 100644 CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj create mode 100644 CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs create mode 100644 CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs create mode 100644 CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs create mode 100644 CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs delete mode 100644 CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs create mode 100644 CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs create mode 100644 CDP4JsonSerializer/SerializerOptions.cs diff --git a/CDP4-SDK.sln b/CDP4-SDK.sln index 4b54bcb1e..399349a7d 100644 --- a/CDP4-SDK.sln +++ b/CDP4-SDK.sln @@ -79,6 +79,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4ServicesMessaging.Tests EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4DalCommon", "CDP4DalCommon\CDP4DalCommon.csproj", "{E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CDP4DalJsonSerializer", "CDP4DalJsonSerializer\CDP4DalJsonSerializer.csproj", "{36C38A02-C1CF-4F4F-AB40-F0A231256B30}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -209,6 +211,10 @@ Global {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Release|Any CPU.Build.0 = Release|Any CPU + {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CDP4-SDK.sln.DotSettings b/CDP4-SDK.sln.DotSettings index bdc00e13d..b148fe695 100644 --- a/CDP4-SDK.sln.DotSettings +++ b/CDP4-SDK.sln.DotSettings @@ -246,7 +246,7 @@ <copyright file="${File.FileName}" company="RHEA System S.A."> Copyright (c) 2015-${CurrentDate.Year} RHEA System S.A. - Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar + Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs b/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs index 769ec3409..1ced51854 100644 --- a/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests.DAL { @@ -36,11 +36,12 @@ namespace CDP4Dal.Tests.DAL using CDP4Common.Helpers; using CDP4Dal.Composition; + using CDP4Dal.DAL; using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4Dal.DAL; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -140,6 +141,7 @@ public void Verify_That_SetIterationId_Works_as_expected() var iteration = new Iteration(); var elementDefinition = new ElementDefinition(); var parameter = new Parameter(); + var list = new List { model, @@ -303,7 +305,10 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w [CDPVersion("1.1.0")] internal class TestDal : Dal { - public override bool IsReadOnly { get { return false; } } + public override bool IsReadOnly + { + get { return false; } + } public TestDal(Credentials credentials) : base() @@ -451,6 +456,7 @@ public override Task> CherryPick(Guid engineeringModelId, Gui internal class DecoratedDal : Dal { public override bool IsReadOnly { get; } + public override Task> Write(IEnumerable operationContainer, IEnumerable files = null) { throw new NotImplementedException(); @@ -566,4 +572,4 @@ public override Task> CherryPick(Guid engineeringModelId, Gui throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs index 4a38275e3..0fb7fadf3 100644 --- a/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -28,10 +28,14 @@ namespace CDP4Dal.Tests using System.Linq; using CDP4Common.CommonData; - using CDP4Common.DTO; + using CDP4Common.DTO; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; - + [TestFixture] public class OperationContainerTestFixture { @@ -42,7 +46,7 @@ public class OperationContainerTestFixture [SetUp] public void SetUp() { - this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; + this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; this.iterationContext = "/EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b/iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"; } @@ -98,9 +102,9 @@ public void VerifyExecutionOfOperationAddAndRemove() var elementDefinition = new ElementDefinition(Guid.NewGuid(), 0); elementDefinition.PartialRoutes.Add("iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); elementDefinition.PartialRoutes.Add("EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b"); - + var clone = elementDefinition.DeepClone(); - var operation = new Operation(elementDefinition, clone, OperationKind.Update); + var operation = new Operation(elementDefinition, clone, OperationKind.Update); var operationContainer = new OperationContainer(this.iterationContext); diff --git a/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs index 740b45252..c749e2325 100644 --- a/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs @@ -1,33 +1,33 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { using CDP4Common.DTO; - using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] diff --git a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs index 7e19fa6e2..6ded42c1c 100644 --- a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs @@ -1,37 +1,37 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion - -using CDP4Common; +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { using System.Collections.Generic; + + using CDP4Common; using CDP4Common.Dto; using CDP4Common.DTO; - using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] @@ -44,16 +44,20 @@ public void VerifyThatConstructorSetsLists() Assert.IsNotNull(testPostOperation.Delete); Assert.IsNotNull(testPostOperation.Create); Assert.IsNotNull(testPostOperation.Update); - Assert.IsNotNull(testPostOperation.Copy); + Assert.IsNotNull(testPostOperation.Copy); } } internal class TestPostOperation : PostOperation { public override List Delete { get; set; } + public override List Create { get; set; } + public override List Update { get; set; } + public override List Copy { get; set; } + public override void ConstructFromOperation(Operation operation) { throw new System.NotImplementedException(); diff --git a/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs index 55b96ae05..c0c750745 100644 --- a/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -34,9 +34,11 @@ namespace CDP4Dal.Tests using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - + using CDP4Dal.Operations; - + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// @@ -131,6 +133,7 @@ public void VerifyThatCreateThingWorksWithAbstractContainer() { Container = this.siteDirectory }; + this.cache.TryAdd(new CacheKey(siteRdl.Iid, null), new Lazy(() => siteRdl)); var cloneRdl = siteRdl.Clone(false); @@ -183,7 +186,7 @@ public void VerifyThatCreateThingTwiceDoesntThrowException() var transaction = new ThingTransaction(transactionContext, this.siteDirectory.Clone(false)); var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); - Assert.That(() => + Assert.That(() => { transaction.Create(phone); transaction.Create(phone); @@ -246,7 +249,6 @@ public void VerifyThatDeleteThingAlreadyDeletedWorks() [Test] public void VerifyThatUpdateContainerWorks() { - var iterationClone = this.iteration.Clone(false); var option1 = new Option(Guid.NewGuid(), this.cache, this.uri); @@ -328,6 +330,7 @@ public void FunctionalTestCase1() emailTrans.Create(email); emailTrans.FinalizeSubTransaction(email, person1_1); + // end add email, verify that email is added to person1_1, (the clone of person1) Assert.AreEqual(2, person1_1Tr.AddedThing.Count()); @@ -339,6 +342,7 @@ public void FunctionalTestCase1() var phone_1Trans = new ThingTransaction(phone_1, person1_1Tr, person1_1); phone_1Trans.CreateOrUpdate(phone_1); phone_1Trans.FinalizeSubTransaction(phone_1, person1_1); + // end update phone // verify that the new reference is used @@ -354,7 +358,6 @@ public void FunctionalTestCase1() Assert.IsTrue(rootTransaction.AddedThing.Contains(phone_1)); Assert.AreEqual(1, cloneSiteDir.Person.Count); - // Create new person var person2 = new Person(); var person2Trans = new ThingTransaction(person2, rootTransaction, cloneSiteDir); @@ -496,7 +499,6 @@ public void FunctionalTestCase2() Assert.IsTrue(siteDirClone.SiteReferenceDataLibrary.Contains(srdl2)); Assert.IsTrue(srdl2.Unit.Contains(unit2)); - // update site rdl1 var srdlC2 = siterdlC1.Clone(false); var srdlC2TRans = new ThingTransaction(srdlC2, rootTransaction, siteDirClone); @@ -829,6 +831,7 @@ public void VerifyThatCascadeDeleteWorksOnAddedThing() transaction.Delete(person.Clone(false)); var operationContainer = transaction.FinalizeTransaction(); + // Update sitedir Assert.AreEqual(1, operationContainer.Operations.Count()); } diff --git a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs index d8e13ce03..ee986c74a 100644 --- a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.NetCore.Tests { @@ -37,17 +37,18 @@ namespace CDP4Dal.NetCore.Tests using CDP4Common.Types; using CDP4Dal.Composition; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using Moq; - + using NUnit.Framework; - + using DomainOfExpertise = CDP4Common.SiteDirectoryData.DomainOfExpertise; using EngineeringModelSetup = CDP4Common.DTO.EngineeringModelSetup; using ModelReferenceDataLibrary = CDP4Common.SiteDirectoryData.ModelReferenceDataLibrary; @@ -129,10 +130,7 @@ public void TearDown() public async Task VerifythatOpenCallAssemblerSynchronizeWithDtos() { var eventReceived = false; - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Open(); @@ -149,20 +147,20 @@ public async Task VerifyThatWriteWithEmptyResponseSendsMessages() writeWithNoResultsTaskCompletionSource.SetResult(new List()); this.mockedDal.Setup(x => x.Open(It.IsAny(), It.IsAny())).Returns(writeWithNoResultsTaskCompletionSource.Task); - this.messageBus.Listen() - .Subscribe(x => - { - if (x.Status == SessionStatus.BeginUpdate) + this.messageBus.Listen() + .Subscribe(x => { - beginUpdateReceived = true; - return; - } + if (x.Status == SessionStatus.BeginUpdate) + { + beginUpdateReceived = true; + return; + } - if (x.Status == SessionStatus.EndUpdate) - { - endUpdateReceived = true; - } - }); + if (x.Status == SessionStatus.EndUpdate) + { + endUpdateReceived = true; + } + }); var context = $"/SiteDirectory/{Guid.NewGuid()}"; @@ -186,13 +184,10 @@ public async Task VerifythatRefreshSynchronizeTheAssembler() var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(this.dalOutputs); this.mockedDal.Setup(x => x.Read(It.IsAny(), It.IsAny(), It.Is(query => query.RevisionNumber == 0))).Returns(readTaskCompletionSource.Task); - + await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); // refresh shouldnt do anything await this.session.Refresh(); @@ -216,10 +211,7 @@ public async Task VerifythatReloadSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Reload(); @@ -277,10 +269,10 @@ public async Task VerifyThatCloseRdlWorks() var rdlDto = new CDP4Common.DTO.SiteReferenceDataLibrary { Iid = Guid.NewGuid() }; var rdlPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary { Iid = rdlDto.Iid, Name = rdlDto.Name, ShortName = rdlDto.ShortName, Container = siteDirectoryPoco }; - + var requiredSiteReferenceDataLibraryDto = new CDP4Common.DTO.SiteReferenceDataLibrary() { Iid = Guid.NewGuid() }; var requiredSiteReferenceDataLibraryPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary(requiredSiteReferenceDataLibraryDto.Iid, this.session.Assembler.Cache, this.uri); - + rdlDto.RequiredRdl = requiredSiteReferenceDataLibraryDto.Iid; rdlPoco.RequiredRdl = requiredSiteReferenceDataLibraryPoco; @@ -303,7 +295,7 @@ public async Task VerifyThatCloseRdlWorks() Lazy requiredRdlToClose; session.Assembler.Cache.TryGetValue(new CacheKey(requiredSiteReferenceDataLibraryPoco.Iid, null), out requiredRdlToClose); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary)requiredRdlToClose.Value); - + Assert.AreEqual(0, session.OpenReferenceDataLibraries.ToList().Count); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary)rdlPocoToClose.Value); @@ -319,7 +311,7 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() rdlDto.RequiredRdl = requiredRdlDto.Iid; siteDirDto.SiteReferenceDataLibrary.Add(rdlDto.Iid); siteDirDto.SiteReferenceDataLibrary.Add(requiredRdlDto.Iid); - + siteDirDto.Person.Add(this.person.Iid); var mrdl = new CDP4Common.DTO.ModelReferenceDataLibrary(Guid.NewGuid(), 0) { RequiredRdl = requiredRdlDto.Iid }; @@ -348,14 +340,15 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() var participant = new CDP4Common.DTO.Participant(Guid.NewGuid(), 0) { Person = this.person.Iid }; modelsetup.Participant.Add(participant.Iid); - var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null){EngineeringModelSetup = modelsetuppoco}; + var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null) { EngineeringModelSetup = modelsetuppoco }; var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); modelPoco.Iteration.Add(iterationPoco); var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(readReturn); + this.mockedDal.Setup( - x => x.Read(It.IsAny(), It.IsAny(), null)) + x => x.Read(It.IsAny(), It.IsAny(), null)) .Returns(readTaskCompletionSource.Task); var thingsToAdd = new List() { siteDirDto, requiredRdlDto, rdlDto, this.person, participant, modelsetup }; @@ -365,7 +358,7 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() this.session.GetType().GetProperty("ActivePerson").SetValue(this.session, JohnDoe, null); await this.session.Read(iterationPoco, null); - + Assert.AreEqual(2, this.session.OpenReferenceDataLibraries.Count()); Lazy requiredRdlToClose; @@ -389,7 +382,7 @@ public async Task VerifyThatCloseModelRdlWorks() siteDir.Model.Add(containerEngModelSetup); modelRdlDto.RequiredRdl = requiredPocoDto.Iid; siteDir.Person.Add(JohnDoe); - + var credentials = new Credentials("admin", "pass", new Uri("http://www.rheagroup.com")); var session2 = new Session(this.mockedDal.Object, credentials, this.messageBus); session2.GetType().GetProperty("ActivePerson").SetValue(session2, JohnDoe, null); @@ -449,6 +442,7 @@ public async Task VerifyThatReadRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; + this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); @@ -518,14 +512,14 @@ public async Task Verify_that_EngineeringModel_returns_result() await this.session.Read(iids); - Assert.That(this.session.Assembler.Cache.ContainsKey(new CacheKey(engineeringModel.Iid, null)), Is.True); + Assert.That(this.session.Assembler.Cache.ContainsKey(new CacheKey(engineeringModel.Iid, null)), Is.True); } [Test] public async Task VerifyThatReadIterationWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) {ShortName = "John"}; + var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid() }; var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); @@ -570,7 +564,7 @@ public async Task VerifyThatReadIterationWorks() var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); iterationToOpen.Container = modelToOpen; - + await this.session.Read(iterationToOpen, activeDomain); this.mockedDal.Verify(x => x.Read(It.Is(i => i.Iid == iterationToOpen.Iid), It.IsAny(), It.IsAny()), Times.Once); @@ -607,7 +601,7 @@ public void Verify_that_when_active_person_is_null_Iteration_is_not_read() var activeDomain = new DomainOfExpertise(Guid.NewGuid(), null, null); var model = new EngineeringModel(Guid.NewGuid(), 1); var iteration = new Iteration(Guid.NewGuid(), 10) { IterationSetup = iterationSetup.Iid }; - + var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); iterationToOpen.Container = modelToOpen; @@ -623,7 +617,7 @@ public void VeriyThatCDPVersionIsSet() this.session = new Session(testDal, credentials, this.messageBus); var version = new Version("1.1.0"); - + Assert.AreEqual(version.Major, this.session.DalVersion.Major); Assert.AreEqual(version.Minor, this.session.DalVersion.Minor); Assert.AreEqual(version.Build, this.session.DalVersion.Build); @@ -664,10 +658,7 @@ public async Task VerifyThatWriteWorksWithEventHandler() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = false; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = false; }; await this.session.Write(new OperationContainer(context)); @@ -681,10 +672,7 @@ public void VerifyThatCancelWriteWorks() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = true; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = true; }; Assert.ThrowsAsync(async () => await this.session.Write(new OperationContainer(context))); @@ -746,11 +734,11 @@ public async Task VerifyCanReadCometTasks() var returnedCometTasks = new List() { - new () + new() { Id = Guid.NewGuid() }, - new () + new() { Id = Guid.NewGuid() }, @@ -788,7 +776,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ReturnsAsync(new LongRunningTaskResult(new CometTask() { Id = Guid.Empty })); - + var cometTask = await this.session.Write(new OperationContainer(context), 1); Assert.Multiple(() => @@ -817,7 +805,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ThrowsAsync(new DalReadException()); - Assert.That(() =>this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); + Assert.That(() => this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); } private void AssignActivePerson() @@ -830,17 +818,30 @@ private void AssignActivePerson() [DalExport("test dal", "test dal description", "1.1.0", DalType.Web)] internal class TestDal : IDal { - public Version SupportedVersion { get {return new Version(1, 0, 0);} } + public Version SupportedVersion + { + get { return new Version(1, 0, 0); } + } - public Version DalVersion { get {return new Version("1.1.0");} } - public IMetaDataProvider MetaDataProvider { get {return new MetaDataProvider();} } + public Version DalVersion + { + get { return new Version("1.1.0"); } + } + + public IMetaDataProvider MetaDataProvider + { + get { return new MetaDataProvider(); } + } /// /// Gets or sets the that uses this /// public ISession Session { get; set; } - public bool IsReadOnly { get { return false; } } + public bool IsReadOnly + { + get { return false; } + } /// /// Write all the s from all the s asynchronously. @@ -958,7 +959,7 @@ public Task> Read(Iteration iteration, CancellationToken canc /// A list of s /// /// - /// Only those s are retunred that the is a in + /// Only those s are retunred that the is a in /// public Task> Read(IEnumerable engineeringModels, CancellationToken cancellationToken) { @@ -1097,4 +1098,4 @@ public Task> CherryPick(Guid engineeringModelId, Guid iterati throw new System.NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.Tests/DAL/DalTestFixture.cs b/CDP4Dal.Tests/DAL/DalTestFixture.cs index beb304103..2645f9d1a 100644 --- a/CDP4Dal.Tests/DAL/DalTestFixture.cs +++ b/CDP4Dal.Tests/DAL/DalTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests.DAL { @@ -36,11 +36,11 @@ namespace CDP4Dal.Tests.DAL using CDP4Common.Helpers; using CDP4Dal.Composition; + using CDP4Dal.DAL; using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4Dal.DAL; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -64,7 +64,7 @@ public void SetUp() [Test] public void Verify_that_the_credentials_are_set_to_Null_when_closed() { - var dal = new TestDal(this.credentials); + var dal = new TestDal(this.credentials); dal.CloseSession(); Assert.IsNull(dal.Credentials); } @@ -140,6 +140,7 @@ public void Verify_That_SetIterationId_Works_as_expected() var iteration = new Iteration(); var elementDefinition = new ElementDefinition(); var parameter = new Parameter(); + var list = new List { model, @@ -206,7 +207,7 @@ public void Verify_that_when_SetIterationContainer_is_called_with_empty_guid_exc public void Verify_That_QueryRequestContext_Returns_Expected_Result() { var testdal = new TestDal(this.credentials); - + var elementDefinitionUri = new Uri("http://www.rheagroup.com/EngineeringModel/00B1FD7E-BE0F-4512-A406-02FCBD63E06A/iteration/0111A76D-346D-4055-A78D-B8215B993DA1/element/E9E8E386-B8BB-44F1-80B9-2C30761EE688"); var elementDefinitionContext = testdal.QueryRequestContext(elementDefinitionUri); Assert.AreEqual("/EngineeringModel/00B1FD7E-BE0F-4512-A406-02FCBD63E06A/iteration/0111A76D-346D-4055-A78D-B8215B993DA1", elementDefinitionContext); @@ -216,7 +217,7 @@ public void Verify_That_QueryRequestContext_Returns_Expected_Result() public void Verify_that_for_a_decorated_dal_the_version_is_set() { var dal = new DecoratedDal(); - Assert.That(dal.DalVersion, Is.EqualTo(new Version(1,1,0))); + Assert.That(dal.DalVersion, Is.EqualTo(new Version(1, 1, 0))); } [Test] @@ -238,7 +239,7 @@ public void Verify_that_OperationContainerFileVerification_throws_an_exception_w var commonFileStore = new CDP4Common.EngineeringModelData.CommonFileStore(Guid.NewGuid(), null, null); engineeringModel.Iteration.Add(iteration); engineeringModel.CommonFileStore.Add(commonFileStore); - + var context = TransactionContextResolver.ResolveContext(commonFileStore); var transaction = new ThingTransaction(context); @@ -246,13 +247,13 @@ public void Verify_that_OperationContainerFileVerification_throws_an_exception_w var file = new CDP4Common.EngineeringModelData.File(Guid.NewGuid(), null, null); var fileRevision = new CDP4Common.EngineeringModelData.FileRevision(Guid.NewGuid(), null, null); - + transaction.Create(file, commonFileStoreClone); transaction.Create(fileRevision, file); var operationContainer = transaction.FinalizeTransaction(); - var files = new List {this.filePath}; + var files = new List { this.filePath }; var testDal = new TestDal(this.credentials); Assert.Throws(() => testDal.TestOperationContainerFileVerification(operationContainer, files)); @@ -277,7 +278,7 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w var commonFileStore = new CDP4Common.EngineeringModelData.CommonFileStore(Guid.NewGuid(), null, null); engineeringModel.Iteration.Add(iteration); engineeringModel.CommonFileStore.Add(commonFileStore); - + var context = TransactionContextResolver.ResolveContext(commonFileStore); var transaction = new ThingTransaction(context); @@ -286,13 +287,13 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w var file = new CDP4Common.EngineeringModelData.File(Guid.NewGuid(), null, null); var fileRevision = new CDP4Common.EngineeringModelData.FileRevision(Guid.NewGuid(), null, null); fileRevision.ContentHash = "1B686ADFA2CAE870A96E5885087337C032781BE6"; - + transaction.Create(file, commonFileStoreClone); transaction.Create(fileRevision, file); var operationContainer = transaction.FinalizeTransaction(); - var files = new List {this.filePath}; + var files = new List { this.filePath }; var testDal = new TestDal(this.credentials); @@ -300,10 +301,13 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w } } - [CDPVersion("1.1.0")] + [CDPVersion("1.1.0")] internal class TestDal : Dal { - public override bool IsReadOnly { get { return false; } } + public override bool IsReadOnly + { + get { return false; } + } public TestDal(Credentials credentials) : base() @@ -410,7 +414,7 @@ public override IEnumerable Update(T thing) { throw new System.NotImplementedException(); } - + public override IEnumerable Delete(T thing) { throw new System.NotImplementedException(); @@ -447,10 +451,11 @@ public override Task> CherryPick(Guid engineeringModelId, Gui } } - [DalExportAttribute("decorateddal","a decorated dal","1.1.0",DalType.Web)] + [DalExportAttribute("decorateddal", "a decorated dal", "1.1.0", DalType.Web)] internal class DecoratedDal : Dal { public override bool IsReadOnly { get; } + public override Task> Write(IEnumerable operationContainer, IEnumerable files = null) { throw new NotImplementedException(); @@ -566,4 +571,4 @@ public override Task> CherryPick(Guid engineeringModelId, Gui throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs b/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs index 4a38275e3..0fb7fadf3 100644 --- a/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs +++ b/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -28,10 +28,14 @@ namespace CDP4Dal.Tests using System.Linq; using CDP4Common.CommonData; - using CDP4Common.DTO; + using CDP4Common.DTO; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; - + [TestFixture] public class OperationContainerTestFixture { @@ -42,7 +46,7 @@ public class OperationContainerTestFixture [SetUp] public void SetUp() { - this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; + this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; this.iterationContext = "/EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b/iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"; } @@ -98,9 +102,9 @@ public void VerifyExecutionOfOperationAddAndRemove() var elementDefinition = new ElementDefinition(Guid.NewGuid(), 0); elementDefinition.PartialRoutes.Add("iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); elementDefinition.PartialRoutes.Add("EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b"); - + var clone = elementDefinition.DeepClone(); - var operation = new Operation(elementDefinition, clone, OperationKind.Update); + var operation = new Operation(elementDefinition, clone, OperationKind.Update); var operationContainer = new OperationContainer(this.iterationContext); diff --git a/CDP4Dal.Tests/Operations/OperationTestFixture.cs b/CDP4Dal.Tests/Operations/OperationTestFixture.cs index 740b45252..c749e2325 100644 --- a/CDP4Dal.Tests/Operations/OperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/OperationTestFixture.cs @@ -1,33 +1,33 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { using CDP4Common.DTO; - using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] diff --git a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs index 7e19fa6e2..6ded42c1c 100644 --- a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs @@ -1,37 +1,37 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion - -using CDP4Common; +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { using System.Collections.Generic; + + using CDP4Common; using CDP4Common.Dto; using CDP4Common.DTO; - using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] @@ -44,16 +44,20 @@ public void VerifyThatConstructorSetsLists() Assert.IsNotNull(testPostOperation.Delete); Assert.IsNotNull(testPostOperation.Create); Assert.IsNotNull(testPostOperation.Update); - Assert.IsNotNull(testPostOperation.Copy); + Assert.IsNotNull(testPostOperation.Copy); } } internal class TestPostOperation : PostOperation { public override List Delete { get; set; } + public override List Create { get; set; } + public override List Update { get; set; } + public override List Copy { get; set; } + public override void ConstructFromOperation(Operation operation) { throw new System.NotImplementedException(); diff --git a/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs b/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs index 8be01a270..c0c750745 100644 --- a/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs +++ b/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -31,12 +31,14 @@ namespace CDP4Dal.Tests using System.Text; using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - + using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// @@ -51,7 +53,7 @@ public class ThingTransactionTestFixture private ConcurrentDictionary> cache; private Uri uri = new Uri("http://www.rheagroup.com"); - + [SetUp] public void Setup() { @@ -65,7 +67,7 @@ public void Setup() iterationSetup.IterationIid = this.iteration.Iid; this.engineeringModel.Iteration.Add(this.iteration); - + this.cache.TryAdd(new CacheKey(this.siteDirectory.Iid, null), new Lazy(() => this.siteDirectory)); this.cache.TryAdd(new CacheKey(this.engineeringModel.Iid, null), new Lazy(() => this.engineeringModel)); this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy(() => this.iteration)); @@ -85,7 +87,7 @@ public void VerifyThatFilePathsAreReturned() var transaction = new ThingTransaction(transactionContext, fileRevision1); transaction.CreateOrUpdate(fileRevision2); - CollectionAssert.AreEqual(transaction.GetFiles(), new [] { filePath }); + CollectionAssert.AreEqual(transaction.GetFiles(), new[] { filePath }); } [Test] @@ -95,7 +97,7 @@ public void VerifyThatCanOnlyUseThingTransactionOnOneTopContainer() var person = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = this.siteDirectory }; var transaction = new ThingTransaction(transactionContext, person); - + var duplicateSiteDirectory = new SiteDirectory(this.siteDirectory.Iid, this.cache, this.uri); var anotherPerson = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = duplicateSiteDirectory }; transaction.CreateOrUpdate(anotherPerson); @@ -109,7 +111,7 @@ public void VerifyThatCanOnlyUseThingTransactionOnOneTopContainer() [Test] public void VerifyThatCreateThingWorks() { - var person = new Person(Guid.NewGuid(), this.cache, this.uri) {Container = this.siteDirectory}; + var person = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = this.siteDirectory }; this.cache.TryAdd(new CacheKey(person.Iid, null), new Lazy(() => person)); var clonePerson = person.Clone(false); @@ -131,6 +133,7 @@ public void VerifyThatCreateThingWorksWithAbstractContainer() { Container = this.siteDirectory }; + this.cache.TryAdd(new CacheKey(siteRdl.Iid, null), new Lazy(() => siteRdl)); var cloneRdl = siteRdl.Clone(false); @@ -152,7 +155,7 @@ public void VerifyThatCreateModelDoesNotWorks() var newModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); - + Assert.Throws(() => new ThingTransaction(transactionContext, newModel)); } @@ -162,7 +165,7 @@ public void VerifyThatCreateSiteDirDoesNotWorks() var newSiteDirectory = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); - + Assert.Throws(() => new ThingTransaction(transactionContext, newSiteDirectory)); } @@ -195,7 +198,7 @@ public void VerifyThatUpdateThingWorks() { var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); this.cache.TryAdd(new CacheKey(phone.Iid, null), new Lazy(() => phone)); - + var clone = phone.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); @@ -208,9 +211,9 @@ public void VerifyThatUpdateThingWorks() [Test] public void VerifyThatUpdateThingThrowsExceptionUponUpdatingExistingCloneWithAnotherClone() { - var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); + var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); this.cache.TryAdd(new CacheKey(phone.Iid, null), new Lazy(() => phone)); - + var clone1 = phone.Clone(false); var clone2 = phone.Clone(false); @@ -246,10 +249,9 @@ public void VerifyThatDeleteThingAlreadyDeletedWorks() [Test] public void VerifyThatUpdateContainerWorks() { - var iterationClone = this.iteration.Clone(false); var option1 = new Option(Guid.NewGuid(), this.cache, this.uri); - + var transactionContext = TransactionContextResolver.ResolveContext(this.iteration); var transaction = new ThingTransaction(transactionContext, iterationClone); transaction.CreateOrUpdate(iterationClone); @@ -272,7 +274,7 @@ public void VerifyThatUpdateContainerWorks() Assert.AreEqual(0, this.iteration.Option.Count); Assert.AreEqual(2, clone.Option.Count); } - + /// /// Create a containment tree under site directory and update /// @@ -328,6 +330,7 @@ public void FunctionalTestCase1() emailTrans.Create(email); emailTrans.FinalizeSubTransaction(email, person1_1); + // end add email, verify that email is added to person1_1, (the clone of person1) Assert.AreEqual(2, person1_1Tr.AddedThing.Count()); @@ -339,6 +342,7 @@ public void FunctionalTestCase1() var phone_1Trans = new ThingTransaction(phone_1, person1_1Tr, person1_1); phone_1Trans.CreateOrUpdate(phone_1); phone_1Trans.FinalizeSubTransaction(phone_1, person1_1); + // end update phone // verify that the new reference is used @@ -353,7 +357,7 @@ public void FunctionalTestCase1() Assert.IsTrue(cloneSiteDir.Person.Contains(person1_1)); Assert.IsTrue(rootTransaction.AddedThing.Contains(phone_1)); Assert.AreEqual(1, cloneSiteDir.Person.Count); - + // Create new person var person2 = new Person(); var person2Trans = new ThingTransaction(person2, rootTransaction, cloneSiteDir); @@ -495,7 +499,6 @@ public void FunctionalTestCase2() Assert.IsTrue(siteDirClone.SiteReferenceDataLibrary.Contains(srdl2)); Assert.IsTrue(srdl2.Unit.Contains(unit2)); - // update site rdl1 var srdlC2 = siterdlC1.Clone(false); var srdlC2TRans = new ThingTransaction(srdlC2, rootTransaction, siteDirClone); @@ -578,7 +581,7 @@ public void VerifyThatCreateDeepWorks() enumValue.Definition.Add(enumValueDef); enumPt.ValueDefinition.Add(enumValue); - + var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); var transaction = new ThingTransaction(transactionContext); transaction.CreateDeep(enumPt); @@ -828,6 +831,7 @@ public void VerifyThatCascadeDeleteWorksOnAddedThing() transaction.Delete(person.Clone(false)); var operationContainer = transaction.FinalizeTransaction(); + // Update sitedir Assert.AreEqual(1, operationContainer.Operations.Count()); } @@ -853,8 +857,8 @@ public void VerifyThatDryCopyWorks() var elementDefinitionClone = elementDefinition.Clone(false); var targetIterationClone = targetIteration.Clone(false); - - var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); + + var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); var transaction = new ThingTransaction(transactionContext); transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.CopyDefaultValuesChangeOwner); @@ -887,7 +891,7 @@ public void VerifyThatCtrlCopyWorks() var elementDefinitionClone = elementDefinition.Clone(false); var targetIterationClone = targetIteration.Clone(false); - + var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); var transaction = new ThingTransaction(transactionContext); transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.CopyKeepValuesChangeOwner); @@ -995,7 +999,7 @@ public void VerifyThatWhenCopyOperationIsInvokedWithNonCopyOperationExceptionIsT Assert.Throws(() => transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.Create)); } - [Test] + [Test] public void VerifyThatCopyThrowsExcpetionCloneThatIsToBeCopiedIsNull() { var sourceModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); @@ -1020,7 +1024,7 @@ public void VerifyThatCopyThrowsExcpetionCloneThatIsToBeCopiedIsNull() Assert.Throws(() => transaction.Copy(null, OperationKind.Copy)); } - [Test] + [Test] public void VerifyThatCopyThrowsExceptionWhenDestinationIsNull() { var sourceModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); @@ -1051,9 +1055,9 @@ public void VerifyThatGetLastCloneCreatedThrowsExceptionWhenThingIsNullOrGuidIsE { var model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); var iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri); - + model.Iteration.Add(iteration); - + var transactionContext = TransactionContextResolver.ResolveContext(iteration); var transaction = new ThingTransaction(transactionContext); @@ -1067,9 +1071,9 @@ public void VerifyThatGetLastCloneCreatedThrowsExceptionWhenThingIsNullOrGuidIsE [Test] public void VerifyThatArgumentNullExceptionIsThrownWhenContextIsNull() { - Assert.Throws(() => new ThingTransaction(null)); + Assert.Throws(() => new ThingTransaction(null)); } - + [Test] public void VerifyThatArgumentNullExceptionIsThrownWhenCloneIsNull() { @@ -1085,7 +1089,7 @@ public void VerifyThatArgumentNullExceptionIsThrownWhenCloneIsNull() var iterationClone = iteration.Clone(false); var elementDefinitionClone = elementDefinition.Clone(false); - Assert.Throws(() => new ThingTransaction(null, null, iterationClone)); + Assert.Throws(() => new ThingTransaction(null, null, iterationClone)); } } } diff --git a/CDP4Dal.Tests/SessionTestFixture.cs b/CDP4Dal.Tests/SessionTestFixture.cs index 6b6b45adf..07b0316fb 100644 --- a/CDP4Dal.Tests/SessionTestFixture.cs +++ b/CDP4Dal.Tests/SessionTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -37,12 +37,12 @@ namespace CDP4Dal.Tests using CDP4Common.Types; using CDP4Dal.Composition; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; using Moq; @@ -130,10 +130,7 @@ public void TearDown() public async Task VerifythatOpenCallAssemblerSynchronizeWithDtos() { var eventReceived = false; - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Open(); @@ -178,10 +175,7 @@ public void VerifyThatOpenCallMightBeCancelled() })); } - Assert.DoesNotThrowAsync(async () => - { - await Task.WhenAll(tasks.ToArray()); - }); + Assert.DoesNotThrowAsync(async () => { await Task.WhenAll(tasks.ToArray()); }); } [Test] @@ -196,18 +190,18 @@ public async Task VerifyThatWriteWithEmptyResponseSendsMessages() this.messageBus.Listen() .Subscribe(x => - { - if (x.Status == SessionStatus.BeginUpdate) { - beginUpdateReceived = true; - return; - } + if (x.Status == SessionStatus.BeginUpdate) + { + beginUpdateReceived = true; + return; + } - if (x.Status == SessionStatus.EndUpdate) - { - endUpdateReceived = true; - } - }); + if (x.Status == SessionStatus.EndUpdate) + { + endUpdateReceived = true; + } + }); var context = $"/SiteDirectory/{Guid.NewGuid()}"; @@ -234,10 +228,7 @@ public async Task VerifythatRefreshSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); // refresh shouldnt do anything await this.session.Refresh(); @@ -267,10 +258,7 @@ public async Task VerifythatReloadSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Reload(); @@ -364,7 +352,7 @@ public async Task VerifyThatCloseRdlWorks() session.Assembler.Cache.TryGetValue(new CacheKey(rdlPoco.Iid, null), out rdlPocoToClose); await session.CloseRdl((CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary)rdlPocoToClose.Value); Assert.AreEqual(1, session.OpenReferenceDataLibraries.ToList().Count); - + await session.Read(rdlPoco); Assert.AreEqual(2, session.OpenReferenceDataLibraries.ToList().Count); @@ -467,14 +455,15 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() var participant = new CDP4Common.DTO.Participant(Guid.NewGuid(), 0) { Person = this.person.Iid }; modelsetup.Participant.Add(participant.Iid); - var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null){EngineeringModelSetup = modelsetuppoco}; + var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null) { EngineeringModelSetup = modelsetuppoco }; var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); modelPoco.Iteration.Add(iterationPoco); var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(readReturn); + this.mockedDal.Setup( - x => x.Read(It.IsAny(), It.IsAny(), null)) + x => x.Read(It.IsAny(), It.IsAny(), null)) .Returns(readTaskCompletionSource.Task); var thingsToAdd = new List() { siteDirDto, requiredRdlDto, rdlDto, this.person, participant, modelsetup }; @@ -568,6 +557,7 @@ public async Task VerifyThatReadRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; + this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); @@ -599,7 +589,7 @@ public async Task VerifyThatReadRdlWorks() public async Task VerifyThatReadIterationWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) {ShortName = "John"}; + var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid() }; var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); @@ -738,10 +728,7 @@ public async Task VerifyThatWriteWorksWithEventHandler() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = false; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = false; }; await this.session.Write(new OperationContainer(context)); @@ -755,10 +742,7 @@ public void VerifyThatCancelWriteWorks() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = true; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = true; }; Assert.ThrowsAsync(async () => await this.session.Write(new OperationContainer(context))); @@ -784,11 +768,11 @@ public async Task VerifyCanCherryPick() categoriesId.Add(Guid.NewGuid()); var elementDefinitionId = Guid.NewGuid(); - cherryPickedThings.Add(new Iteration(){Iid = engineeringModelId, Element = new List{elementDefinitionId}}); - cherryPickedThings.Add(new ElementDefinition(){Iid = elementDefinitionId, Category = new List { categoriesId[0] }}); + cherryPickedThings.Add(new Iteration() { Iid = engineeringModelId, Element = new List { elementDefinitionId } }); + cherryPickedThings.Add(new ElementDefinition() { Iid = elementDefinitionId, Category = new List { categoriesId[0] } }); readThings = (await this.session.CherryPick(engineeringModelId, iterationId, classKinds, categoriesId)).ToList(); - + Assert.Multiple(() => { Assert.That(readThings, Is.Not.Empty); @@ -893,7 +877,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ReturnsAsync(new LongRunningTaskResult(new CometTask() { Id = Guid.Empty })); - + var cometTask = await this.session.Write(new OperationContainer(context), 1); Assert.Multiple(() => @@ -922,8 +906,9 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ThrowsAsync(new DalReadException()); - Assert.That(() =>this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); + Assert.That(() => this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); } + private void AssignActivePerson() { var johnDoe = new Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; @@ -934,16 +919,30 @@ private void AssignActivePerson() [DalExport("test dal", "test dal description", "1.1.0", DalType.Web)] internal class TestDal : IDal { - public Version SupportedVersion { get {return new Version(1, 0, 0);} } - public Version DalVersion { get {return new Version("1.1.0");} } - public IMetaDataProvider MetaDataProvider { get {return new MetaDataProvider();} } + public Version SupportedVersion + { + get { return new Version(1, 0, 0); } + } + + public Version DalVersion + { + get { return new Version("1.1.0"); } + } + + public IMetaDataProvider MetaDataProvider + { + get { return new MetaDataProvider(); } + } /// /// Gets or sets the that uses this /// public ISession Session { get; set; } - public bool IsReadOnly { get { return false; } } + public bool IsReadOnly + { + get { return false; } + } /// /// Write all the s from all the s asynchronously. @@ -1184,4 +1183,4 @@ public Task> CherryPick(Guid engineeringModelId, Guid iterati throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal/DAL/Dal.cs b/CDP4Dal/DAL/Dal.cs index 578de2fb5..425bf12ed 100644 --- a/CDP4Dal/DAL/Dal.cs +++ b/CDP4Dal/DAL/Dal.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.DAL { @@ -36,15 +36,16 @@ namespace CDP4Dal.DAL using CDP4Common.DTO; using CDP4Common.Helpers; using CDP4Common.MetaInfo; - - using CDP4Dal.Operations; + using CDP4Dal.Composition; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NLog; - + using Iteration = CDP4Common.DTO.Iteration; using Thing = CDP4Common.DTO.Thing; @@ -217,7 +218,7 @@ protected Dal() /// The /// /// an await-able that returns a array. - public abstract Task ReadFile(Thing thing, CancellationToken cancellationToken) ; + public abstract Task ReadFile(Thing thing, CancellationToken cancellationToken); /// /// Creates the specified on a data source @@ -438,7 +439,7 @@ public bool TryExtractIterationIdfromUri(Uri uri, out Guid iterationId) } catch (Exception ex) { - Logger.Warn(ex,"The Iteration identifier could not be exracted from {0}", uri); + Logger.Warn(ex, "The Iteration identifier could not be exracted from {0}", uri); iterationId = Guid.Empty; return false; @@ -543,4 +544,4 @@ protected virtual void SetCdpVersion() } } } -} \ No newline at end of file +} diff --git a/CDP4Dal/DAL/IDal.cs b/CDP4Dal/DAL/IDal.cs index 368491b71..179a49356 100644 --- a/CDP4Dal/DAL/IDal.cs +++ b/CDP4Dal/DAL/IDal.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.DAL { @@ -35,7 +35,8 @@ namespace CDP4Dal.DAL using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using Thing = CDP4Common.DTO.Thing; @@ -63,7 +64,7 @@ public interface IDal /// Gets the value indicating whether this is read only /// bool IsReadOnly { get; } - + /// /// Write all the s from all the s asynchronously. /// @@ -91,7 +92,7 @@ public interface IDal /// A list of s that has been created or updated since the last Read or Write operation. /// Task> Write(OperationContainer operationContainer, IEnumerable files = null); - + /// /// Write all the s from an asynchronously for a possible long running task. /// @@ -276,7 +277,7 @@ public interface IDal /// A collection of s /// The /// A of type of read - Task> CherryPick(Guid engineeringModelId, Guid iterationId, IEnumerable classKinds, + Task> CherryPick(Guid engineeringModelId, Guid iterationId, IEnumerable classKinds, IEnumerable categoriesId, CancellationToken cancellationToken); } -} \ No newline at end of file +} diff --git a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs index 5b245e8b4..4296520e1 100644 --- a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -29,6 +29,8 @@ namespace CDP4Dal.Exceptions using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + /// /// A is thrown when an is invalid or incomplete, /// or one of the contained s is invalid or incomplete. diff --git a/CDP4Dal/Exceptions/InvalidOperationKindException.cs b/CDP4Dal/Exceptions/InvalidOperationKindException.cs index b25a089ba..bad5c8d8b 100644 --- a/CDP4Dal/Exceptions/InvalidOperationKindException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationKindException.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -29,9 +29,11 @@ namespace CDP4Dal.Exceptions using CDP4Dal.DAL; + using CDP4DalCommon.Protocol.Operations; + /// /// A InvalidOperationKindException is thrown whenever an contains - /// that are not supported by the implementation of an + /// that are not supported by the implementation of an /// [Serializable] public class InvalidOperationKindException : Exception diff --git a/CDP4Dal/ISession.cs b/CDP4Dal/ISession.cs index 75213100e..b89e6486b 100644 --- a/CDP4Dal/ISession.cs +++ b/CDP4Dal/ISession.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal { @@ -33,13 +33,13 @@ namespace CDP4Dal using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; + using CDP4Dal.Operations; + using CDP4Dal.Permission; - using CDP4DalCommon.Tasks; - - using Permission; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; /// /// The interface encapsulates an and @@ -55,7 +55,7 @@ public interface ISession /// /// Gets the that are use to connect to the data source /// - Credentials Credentials { get; } + Credentials Credentials { get; } /// /// Gets all the s that the active person is linked with. @@ -106,7 +106,7 @@ public interface ISession /// /// Gets the name of the session which is the concatentation of the data-source uri and the active person /// - string Name { get; } + string Name { get; } /// /// Gets the list of that are currently open in the running application. @@ -116,7 +116,7 @@ public interface ISession /// /// Gets the list of s that are currently open with the active and /// - IReadOnlyDictionary > OpenIterations { get; } + IReadOnlyDictionary> OpenIterations { get; } /// /// Gets the that handles messaging for this session diff --git a/CDP4Dal/Operations/IThingTransaction.cs b/CDP4Dal/Operations/IThingTransaction.cs index f979f8ddd..664098d16 100644 --- a/CDP4Dal/Operations/IThingTransaction.cs +++ b/CDP4Dal/Operations/IThingTransaction.cs @@ -1,35 +1,38 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { using System; using System.Collections.Generic; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.Types; + using CDP4DalCommon.Protocol.Operations; + /// /// The interface operations /// @@ -190,4 +193,4 @@ public interface IThingTransaction /// The sub- void Merge(IThingTransaction subTransaction); } -} \ No newline at end of file +} diff --git a/CDP4Dal/Operations/LongRunningTaskResult.cs b/CDP4Dal/Operations/LongRunningTaskResult.cs index b493cb5c4..c0b4f7d5a 100644 --- a/CDP4Dal/Operations/LongRunningTaskResult.cs +++ b/CDP4Dal/Operations/LongRunningTaskResult.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -28,7 +28,7 @@ namespace CDP4Dal.Operations using CDP4Common.DTO; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; /// /// Handle the returned data of a possible long running task diff --git a/CDP4Dal/Operations/OperationContainer.cs b/CDP4Dal/Operations/OperationContainer.cs index e6b2e64ba..2b66a7a9b 100644 --- a/CDP4Dal/Operations/OperationContainer.cs +++ b/CDP4Dal/Operations/OperationContainer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { @@ -30,6 +30,8 @@ namespace CDP4Dal.Operations using CDP4Common.DTO; using CDP4Common.Helpers; + using CDP4DalCommon.Protocol.Operations; + /// /// A container for the s that need to be executed on a data source using an implementation of /// @@ -62,7 +64,7 @@ public OperationContainer(string context, int? topContainerRevNumber = null) this.Token = TokenGenerator.GenerateRandomToken(); this.Context = context; - + this.operations = new List(); this.TopContainerRevisionNumber = topContainerRevNumber; } @@ -94,10 +96,7 @@ public OperationContainer(string context, int? topContainerRevNumber = null) /// public IEnumerable Operations { - get - { - return this.operations; - } + get { return this.operations; } } /// @@ -136,7 +135,7 @@ private void ValidateContextOfOperation(Operation operation) /// public void RemoveOperation(Operation operation) { - this.operations.Remove(operation); + this.operations.Remove(operation); } } -} \ No newline at end of file +} diff --git a/CDP4Dal/Operations/OperationKindExtensions.cs b/CDP4Dal/Operations/OperationKindExtensions.cs index a646933fc..f3b75c509 100644 --- a/CDP4Dal/Operations/OperationKindExtensions.cs +++ b/CDP4Dal/Operations/OperationKindExtensions.cs @@ -1,31 +1,33 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Nathanael Smiechowski -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { using CDP4Common.DTO; + using CDP4DalCommon.Protocol.Operations; + /// /// Utils class to provide OperationKind Extensions to CDP4Dal /// diff --git a/CDP4Dal/Operations/ThingTransaction.cs b/CDP4Dal/Operations/ThingTransaction.cs index 2a12d04c0..8b74fb5c0 100644 --- a/CDP4Dal/Operations/ThingTransaction.cs +++ b/CDP4Dal/Operations/ThingTransaction.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details.copy -// +// Lesser General Public License for more details. +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { @@ -31,15 +31,17 @@ namespace CDP4Dal.Operations using System.Reflection; using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.Extensions; using CDP4Common.Polyfills; using CDP4Common.SiteDirectoryData; - using CDP4Common.CommonData; using CDP4Common.Types; using CDP4Dal.Exceptions; + using CDP4DalCommon.Protocol.Operations; + using NLog; /// @@ -92,10 +94,10 @@ public class ThingTransaction : IThingTransaction /// public ThingTransaction(TransactionContext transactionContext, Thing clone = null) { - this.TransactionContext = - transactionContext ?? + this.TransactionContext = + transactionContext ?? throw new ArgumentNullException(nameof(transactionContext), $"The {nameof(transactionContext)} may not be null"); - + this.addedThing = new List(); this.updatedThing = new Dictionary(); this.deletedThing = new List(); @@ -137,7 +139,7 @@ public ThingTransaction(Thing clone, IThingTransaction parentTransaction, Thing { throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null."); } - + this.TransactionContext = parentTransaction.TransactionContext; this.addedThing = new List(); @@ -299,18 +301,19 @@ public void CreateOrUpdate(Thing clone) throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null"); } - if(this.UpdatedThing.Values.Any(x => x == clone) || this.AddedThing.Any(x => x == clone)) + if (this.UpdatedThing.Values.Any(x => x == clone) || this.AddedThing.Any(x => x == clone)) { return; } - if(this.UpdatedThing.Values.Any(x => x.Iid == clone.Iid) || this.AddedThing.Any(x => x.Iid == clone.Iid)) + if (this.UpdatedThing.Values.Any(x => x.Iid == clone.Iid) || this.AddedThing.Any(x => x.Iid == clone.Iid)) { return; } var UpdatedThing = this.GetUpdatedThing(clone); - if(UpdatedThing != null) + + if (UpdatedThing != null) { if (clone.Iid == Guid.Empty) { @@ -337,7 +340,7 @@ public void Delete(Thing clone, Thing containerClone = null) { throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null."); } - + if (this.DeletedThing.Any(x => x.Iid == clone.Iid)) { return; @@ -363,6 +366,7 @@ public void Delete(Thing clone, Thing containerClone = null) { // remove potential reference from the list of updated thing in the current transaction var updatedThingKey = this.UpdatedThing.Keys.SingleOrDefault(x => x.Iid == clone.Iid); + if (updatedThingKey != null) { this.updatedThing.Remove(updatedThingKey); @@ -375,6 +379,7 @@ public void Delete(Thing clone, Thing containerClone = null) { // remove from the list of added thing var thingInAddedList = this.AddedThing.SingleOrDefault(x => x.Iid == clone.Iid); + if (thingInAddedList != null) { this.addedThing.Remove(thingInAddedList); @@ -434,7 +439,7 @@ public void Copy(Thing clone, OperationKind operationKind) { throw new ArgumentException("The copy operation may only be performed with Copy or CopyDefaultValuesChangeOwner or CopyKeepValues or CopyKeepValuesChangeOwner", nameof(operationKind)); } - + var original = this.GetUpdatedThing(clone); // setting a new iid for the copy @@ -445,7 +450,7 @@ public void Copy(Thing clone, OperationKind operationKind) { return; } - + // setting a new iid for the copy clone.Iid = Guid.NewGuid(); this.copiedThing.Add(originalCopyPair, operationKind); @@ -469,13 +474,14 @@ public Thing GetClone(Thing thing) } var clone = this.UpdatedThing.Values.SingleOrDefault(x => x.Iid == thing.Iid); + if (clone != null) { return clone; } clone = this.AddedThing.SingleOrDefault(x => x.Iid == thing.Iid); - + return clone; } @@ -498,6 +504,7 @@ public Thing GetLastCloneCreated(Thing thing) var allAddedThing = this.GetAllAddedThings().ToList(); var clone = allAddedThing.SingleOrDefault(x => x.Iid == thing.Iid); + if (clone != null) { return clone; @@ -505,7 +512,7 @@ public Thing GetLastCloneCreated(Thing thing) var allUpdatedThing = this.GetAllUpdatedThings().ToList(); clone = allUpdatedThing.SingleOrDefault(x => x.Iid == thing.Iid); - + return clone; } @@ -549,8 +556,8 @@ public void FinalizeSubTransaction(Thing clone, Thing containerclone, Thing next foreach ( var addedThing in - this.AddedThing.Where( - x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) + this.AddedThing.Where( + x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) { if (!addedThing.IsContainedBy(rootClone.Iid)) { @@ -560,6 +567,7 @@ var addedThing in // the clone should have been added var containerOfAddedThing = this.GetClone(addedThing.Container); + if (containerOfAddedThing == null) { throw new TransactionException("could not find the corresponding clone for the container of the added thing added outside the chain of transaction."); @@ -570,8 +578,8 @@ var addedThing in foreach ( var updatedThing in - this.UpdatedThing.Values.Where( - x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) + this.UpdatedThing.Values.Where( + x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) { if (!updatedThing.IsContainedBy(rootClone.Iid)) { @@ -581,6 +589,7 @@ var updatedThing in // the clone should have been added var containerOfUpdatedThing = this.GetClone(updatedThing.Container); + if (containerOfUpdatedThing == null) { throw new TransactionException( @@ -605,7 +614,7 @@ public OperationContainer FinalizeTransaction() } this.FilterOperationCausedByDelete(); - + var context = this.TransactionContext.ContextRoute(); var operationContainer = new OperationContainer(context, this.GetTopContainerRevisionNumber()); @@ -629,7 +638,7 @@ public string[] GetFiles() { if (string.IsNullOrWhiteSpace(thing.ContentHash)) { - throw new InvalidOperationException($"File {thing.LocalPath} cannot be saved because of an empty ContentHash" ); + throw new InvalidOperationException($"File {thing.LocalPath} cannot be saved because of an empty ContentHash"); } files.Add(thing.LocalPath); @@ -649,7 +658,8 @@ private Thing GetUpdatedThing(Thing clone) var allUpdatedThings = this.GetAllUpdatedThings().ToList(); var updatedThing = allUpdatedThings.SingleOrDefault(x => x.Iid == clone.Iid); - if(updatedThing != null) + + if (updatedThing != null) { if (updatedThing == clone) { @@ -662,6 +672,7 @@ private Thing GetUpdatedThing(Thing clone) // case2: the updated thing is already in the transaction as an added thing var allAddedThings = this.GetAllAddedThings().ToList(); updatedThing = allAddedThings.SingleOrDefault(x => x.Iid == clone.Iid); + if (updatedThing != null) { if (updatedThing == clone) @@ -681,6 +692,7 @@ private Thing GetUpdatedThing(Thing clone) // case3: the cache does not contain the key, its a new var lazy = clone.Cache.SingleOrDefault(x => Equals(x.Key, clone.CacheKey)).Value; + if (lazy == null) { return null; @@ -688,6 +700,7 @@ private Thing GetUpdatedThing(Thing clone) // case4: the updated thing is the original updatedThing = lazy.Value; + if (updatedThing == clone) { throw new InvalidOperationException("The transaction only accepts clones."); @@ -703,6 +716,7 @@ private Thing GetUpdatedThing(Thing clone) private IEnumerable GetAllAddedThings() { var allAddedThing = this.AddedThing.ToList(); + if (this.ParentTransaction != null) { this.PopulateAllAddedThingsList(this.ParentTransaction, allAddedThing); @@ -720,6 +734,7 @@ private void PopulateAllAddedThingsList(IThingTransaction transaction, List allAddedThing.All(y => y.Iid != x.Iid)); allAddedThing.AddRange(thingsToAdd); + if (transaction.ParentTransaction != null) { this.PopulateAllAddedThingsList(transaction.ParentTransaction, allAddedThing); @@ -733,6 +748,7 @@ private void PopulateAllAddedThingsList(IThingTransaction transaction, List GetAllUpdatedThings() { var allUpdatedThings = this.UpdatedThing.Values.ToList(); + if (this.ParentTransaction != null) { this.PopulateAllUpdatedThingsList(this.ParentTransaction, allUpdatedThings); @@ -750,6 +766,7 @@ private void PopulateAllUpdatedThingsList(IThingTransaction transaction, List allUpdatedThing.All(y => y.Iid != x.Iid)); allUpdatedThing.AddRange(thingsToAdd); + if (transaction.ParentTransaction != null) { this.PopulateAllUpdatedThingsList(transaction.ParentTransaction, allUpdatedThing); @@ -765,14 +782,15 @@ private void PopulateAllUpdatedThingsList(IThingTransaction transaction, List) }); + var findIndexMethod = containerProperty.PropertyType.GetMethod("FindIndex", new[] { typeof(Predicate) }); Predicate predicate = x => x.Iid == thing.Iid; - var index = (int)(findIndexMethod?.Invoke(containerList, new object[] { predicate })??-1); + var index = (int)(findIndexMethod?.Invoke(containerList, new object[] { predicate }) ?? -1); + if (index != -1) { // Get the indexer property, by default the indexer property name is "Item" @@ -809,6 +827,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next Predicate predicate = x => x.Iid == thing.Iid; var index = (int)findIndexMethod.Invoke(containerList, new object[] { predicate }); + if (index != -1) { // Get the indexer property, by default the indexer property name is "Item" @@ -822,7 +841,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next { // normal add var addMethod = orderedListProperty.PropertyType.GetMethod("Add"); - addMethod.Invoke(containerList, new object[] {thing}); + addMethod.Invoke(containerList, new object[] { thing }); } else { @@ -830,6 +849,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next var indexOfMethod = orderedListProperty.PropertyType.GetMethod("IndexOf"); var index = indexOfMethod.Invoke(containerList, new object[] { nextThing }) as int?; + if (index == -1 || !index.HasValue) { throw new InvalidOperationException("The Thing before which the new item needs to be inserted does not exist."); @@ -850,14 +870,15 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next private void RemoveThingFromContainer(Thing thing) { var containers = this.AddedThing.Concat(this.UpdatedThing.Values); - + var thingType = thing.GetType(); Thing originalThing = null; + if (thing.Cache != null && thing.Cache.ContainsKey(thing.CacheKey)) { var result = thing.Cache.TryGetValue(thing.CacheKey, out var lazyThing); - originalThing = (result)? lazyThing.Value : null; + originalThing = (result) ? lazyThing.Value : null; } // Find in all the thing in the transaction the potential container that contains the current thing @@ -877,7 +898,7 @@ private void RemoveThingFromContainer(Thing thing) var matchingPropertyInfos = containerType.GetProperties().Where(x => x.PropertyType.QueryIsGenericType() && (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || - x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && + x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && x.PropertyType.GetGenericArguments().Single().QueryIsAssignableFrom(thingType)).ToList(); foreach (var propertyInfo in matchingPropertyInfos) @@ -886,6 +907,7 @@ private void RemoveThingFromContainer(Thing thing) var containerList = propertyInfo.GetValue(container) as IEnumerable; Thing thingToRemove = null; + foreach (Thing containedThing in containerList) { if (containedThing.Iid == thing.Iid) @@ -900,6 +922,7 @@ private void RemoveThingFromContainer(Thing thing) } var success = (bool)removeMethod.Invoke(containerList, new object[] { thingToRemove }); + if (success) { thingToRemove.Container = null; @@ -921,6 +944,7 @@ private void InitializeSubTransaction(ThingTransaction subTransaction, Thing con if (containerClone != null) { var currentContainertype = containerClone.GetType(); + if (!containerType.QueryIsAssignableFrom(currentContainertype)) { throw new InvalidOperationException("The specified container is not allowed as a container."); @@ -949,6 +973,7 @@ private void InitializeSubTransaction(ThingTransaction subTransaction, Thing con private void AddChainOfContainers(Thing clone) { var topOperationClone = this.GetOperationRootClone(); + if (!clone.IsContainedBy(topOperationClone.Iid)) { return; @@ -972,6 +997,7 @@ private void AddChainOfContainers(Thing clone) // add a new clone if newContainerClone is not contained by the current operation's chain of clones var containerType = transaction.AssociatedClone.GetType(); var container = clone.GetContainerOfType(containerType); + if (container == null) { return; @@ -992,6 +1018,7 @@ private Thing GetOperationRootClone() { var rootClone = this.AssociatedClone; var parent = this.ParentTransaction; + while (parent != null) { rootClone = parent.AssociatedClone ?? rootClone; @@ -1008,9 +1035,11 @@ private Thing GetOperationRootClone() private IEnumerable GetChainOfSubTransactions() { var parent = this.ParentTransaction; + while (parent != null) { yield return parent; + parent = parent.ParentTransaction; } } @@ -1027,6 +1056,7 @@ private IEnumerable GetChainOfSubTransactions() private void UpdateContainer(Thing clone, Thing containerclone, Thing nextThing = null) { var containerInformation = clone.GetContainerInformation(); + if (!containerInformation.Item1.IsInstanceOfType(containerclone)) { throw new InvalidOperationException("The containerClone does not have the right type"); @@ -1055,6 +1085,7 @@ private void UpdateContainer(Thing clone, Thing containerclone, Thing nextThing private void AddCloneToContainer(Thing clone, Thing containerclone, Thing nextThing = null) { var containerInformation = clone.GetContainerInformation(); + if (!containerInformation.Item1.IsInstanceOfType(containerclone)) { throw new InvalidOperationException("The containerClone does not have the right type"); @@ -1095,6 +1126,7 @@ public void Merge(IThingTransaction subTransaction) } var existingThing = this.AddedThing.SingleOrDefault(t => t.Iid == thing.Iid); + if (existingThing != null) { // replace the current thing with the one from the sub-transaction @@ -1112,6 +1144,7 @@ public void Merge(IThingTransaction subTransaction) if (this.UpdatedThing.ContainsKey(keyValuePair.Key)) { var parentKeyValue = this.UpdatedThing.Single(x => x.Key == keyValuePair.Key); + if (parentKeyValue.Value != keyValuePair.Value) { throw new InvalidOperationException("2 clones have been created for the same thing."); @@ -1122,6 +1155,7 @@ public void Merge(IThingTransaction subTransaction) // check if the key in a sub-transaction correspond to a value in the current one var existingKeyValue = this.UpdatedThing.SingleOrDefault(x => x.Value == keyValuePair.Key); + if (existingKeyValue.Key != null) { this.updatedThing[existingKeyValue.Key] = keyValuePair.Value; @@ -1249,7 +1283,7 @@ private void CreateCopyThingOperation(OperationContainer operationContainer) if (copyOperationKind.IsCopyOperation()) { operationContainer.AddOperation(new Operation(original, copy, copyOperationKind)); - } + } } } @@ -1273,7 +1307,8 @@ private int GetTopContainerRevisionNumber() things.AddRange(this.DeletedThing); things.AddRange(this.CopiedThing.Select(x => x.Key.Item2)); - var distinctTopContainer = things.Select(x => x.TopContainer).DistinctBy(t => t.Iid).ToList(); + var distinctTopContainer = things.Select(x => x.TopContainer).DistinctBy(t => t.Iid).ToList(); + if (distinctTopContainer.Count != 1) { throw new InvalidOperationException("multiple top container updates in one transaction, operation not allowed."); @@ -1290,18 +1325,21 @@ private void FilterOperationCausedByDelete() // filter out the added thing or updated thing that have been marked as deleted // filter out the contained thing of a deleted thing var markedForDeletion = this.DeletedThing.ToList(); + foreach (var thing in markedForDeletion) { var cloneType = thing.GetType(); + var containersInfo = cloneType.GetProperties().Where(x => - x.PropertyType.QueryIsGenericType() && - (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || - x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && - typeof(Thing).QueryIsAssignableFrom(x.PropertyType.GetGenericArguments().Single())).ToList(); + x.PropertyType.QueryIsGenericType() && + (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || + x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && + typeof(Thing).QueryIsAssignableFrom(x.PropertyType.GetGenericArguments().Single())).ToList(); foreach (var containerInfo in containersInfo) { var container = (IEnumerable)containerInfo.GetValue(thing); + foreach (Thing containedThing in container) { this.RemoveThingFromOperationLists(containedThing); @@ -1320,6 +1358,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) { // remove it from the list of updated thing in the current transaction var updatedThingKey = this.UpdatedThing.Keys.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (updatedThingKey != null) { this.updatedThing.Remove(updatedThingKey); @@ -1327,6 +1366,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) // remove from the list of added thing var thingInAddedList = this.AddedThing.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (thingInAddedList != null) { this.addedThing.Remove(thingInAddedList); @@ -1336,6 +1376,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) if (!thingToRemove.IsCached()) { var thingInDeletedList = this.DeletedThing.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (thingInDeletedList != null) { this.deletedThing.Remove(thingInDeletedList); @@ -1343,4 +1384,4 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) } } } -} \ No newline at end of file +} diff --git a/CDP4Dal/Session.cs b/CDP4Dal/Session.cs index 302bb5b17..f81da80a2 100644 --- a/CDP4Dal/Session.cs +++ b/CDP4Dal/Session.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal { @@ -47,7 +47,8 @@ namespace CDP4Dal using CDP4Dal.Operations; using CDP4Dal.Permission; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NLog; @@ -494,7 +495,7 @@ public async Task Read(ReferenceDataLibrary rdl) throw new InvalidOperationException("The ReferenceDataLibrary cannot be read when the ActivePerson is null; The Open method must be called prior to any of the Read methods"); } - await this.Read((Thing) rdl); + await this.Read((Thing)rdl); this.AddRdlToOpenList(rdl); } @@ -524,7 +525,7 @@ public async Task Read(IEnumerable engineeringModels) } logger.Info("Session.Read {EngineeringModel} {0}", !engineeringModels.Any() ? "*" : $"EngineeringModel/{engineeringModels.ToShortGuidArray()}"); - + // Create the token source var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenKey = Guid.NewGuid(); @@ -874,7 +875,7 @@ public Task Write(OperationContainer operationContainer) { var filesList = this.BeforeDalWriteAndProcessFiles(operationContainer, files); var longRunningTaskResult = await this.Dal.Write(operationContainer, waitTime, filesList); - + if (longRunningTaskResult.IsWaitTimeReached) { this.cometTasks[longRunningTaskResult.Task.Id] = longRunningTaskResult.Task; @@ -1179,7 +1180,7 @@ private IEnumerable GetSiteDirectoryAndActiveIterations() .Select(x => x.Value.Value) .Where(x => x is SiteDirectory - || x is Iteration && ((Iteration) x).IterationSetup.FrozenOn == null && this.OpenIterations.ContainsKey((Iteration) x) + || x is Iteration && ((Iteration)x).IterationSetup.FrozenOn == null && this.OpenIterations.ContainsKey((Iteration)x) ) .ToList(); } @@ -1246,7 +1247,7 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo return; } - var activeParticipant = ((EngineeringModel) iteration.Container).EngineeringModelSetup.Participant.SingleOrDefault(p => p.Person == this.ActivePerson); + var activeParticipant = ((EngineeringModel)iteration.Container).EngineeringModelSetup.Participant.SingleOrDefault(p => p.Person == this.ActivePerson); if (activeParticipant == null) { @@ -1255,7 +1256,7 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo this.openIterations.Add(iteration, new Tuple(activeDomain, activeParticipant)); - var modelRdl = ((EngineeringModel) iteration.Container).EngineeringModelSetup.RequiredRdl.Single(); + var modelRdl = ((EngineeringModel)iteration.Container).EngineeringModelSetup.RequiredRdl.Single(); this.AddRdlToOpenList(modelRdl); } diff --git a/CDP4Dal/Operations/Operation.cs b/CDP4DalCommon/Protocol/Operations/Operation.cs similarity index 79% rename from CDP4Dal/Operations/Operation.cs rename to CDP4DalCommon/Protocol/Operations/Operation.cs index 735cd1064..95fc49180 100644 --- a/CDP4Dal/Operations/Operation.cs +++ b/CDP4DalCommon/Protocol/Operations/Operation.cs @@ -1,68 +1,68 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4Dal.Operations -{ - using CDP4Common.DTO; - - /// - /// The change that is to be supplied to the data source via a Data-Access-Layer implementation - /// - public class Operation - { - /// - /// Initializes a new instance of the class. - /// - /// - /// The original fom the local domain store. - /// - /// - /// The modified - /// - /// - /// the kind of operation that is to be executed - /// - public Operation(Thing originalThing, Thing modifiedThing, OperationKind operationKind) - { - this.OriginalThing = originalThing; - this.ModifiedThing = modifiedThing; - this.OperationKind = operationKind; - } - - /// - /// Gets the kind of operation represented by this object. - /// - public OperationKind OperationKind { get; internal set; } - - /// - /// Gets the original that is the subject of the . - /// - public Thing OriginalThing { get; internal set; } - - /// - /// Gets the modified that is the subject of the . - /// - public Thing ModifiedThing { get; internal set; } - } -} +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalCommon.Protocol.Operations +{ + using CDP4Common.DTO; + + /// + /// The change that is to be supplied to the data source via a Data-Access-Layer implementation + /// + public class Operation + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The original fom the local domain store. + /// + /// + /// The modified + /// + /// + /// the kind of operation that is to be executed + /// + public Operation(Thing originalThing, Thing modifiedThing, OperationKind operationKind) + { + this.OriginalThing = originalThing; + this.ModifiedThing = modifiedThing; + this.OperationKind = operationKind; + } + + /// + /// Gets the kind of operation represented by this object. + /// + public OperationKind OperationKind { get; internal set; } + + /// + /// Gets the original that is the subject of the . + /// + public Thing OriginalThing { get; internal set; } + + /// + /// Gets the modified that is the subject of the . + /// + public Thing ModifiedThing { get; internal set; } + } +} diff --git a/CDP4Dal/Operations/OperationKind.cs b/CDP4DalCommon/Protocol/Operations/OperationKind.cs similarity index 84% rename from CDP4Dal/Operations/OperationKind.cs rename to CDP4DalCommon/Protocol/Operations/OperationKind.cs index d4addde4b..d631bd5b0 100644 --- a/CDP4Dal/Operations/OperationKind.cs +++ b/CDP4DalCommon/Protocol/Operations/OperationKind.cs @@ -1,90 +1,90 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4Dal.Operations -{ - using CDP4Common.DTO; - - /// - /// The kind of acting on the object. - /// - public enum OperationKind - { - /// - /// specifies that the on the is a Create operation - /// - Create, - - /// - /// specifies that the on the is an Update operation - /// - Update, - - /// - /// specifies that the on the is a Delete operation - /// - Delete, - - /// - /// specifies that the on the is a Move operation - /// - Move, - - /// - /// specifies that the on the is a "shift" Copy operation - /// - /// - /// If are copied their value-sets shall contain default "-" values. - /// A copy shall keep its original owner - /// - Copy, - - /// - /// specifies that the on the is a "ctrl" Copy operation - /// - /// - /// If are copied their value-sets shall contain original values. - /// A copy shall have its owner set to the active one in the target destination. - /// - CopyKeepValuesChangeOwner, - - /// - /// specifies that the on the is a "dry" Copy operation - /// - /// - /// If are copied their value-sets shall contain default "-" values. - /// A copy shall have its owner set to the active one in the target destination. - /// - CopyDefaultValuesChangeOwner, - - /// - /// specifies that the on the is a "ctrl + shift" Copy operation - /// - /// - /// If are copied their value-sets shall contain the original values. - /// A copy shall keep its original owner - /// - CopyKeepValues - } -} \ No newline at end of file +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalCommon.Protocol.Operations +{ + using CDP4Common.DTO; + + /// + /// The kind of acting on the object. + /// + public enum OperationKind + { + /// + /// specifies that the on the is a Create operation + /// + Create, + + /// + /// specifies that the on the is an Update operation + /// + Update, + + /// + /// specifies that the on the is a Delete operation + /// + Delete, + + /// + /// specifies that the on the is a Move operation + /// + Move, + + /// + /// specifies that the on the is a "shift" Copy operation + /// + /// + /// If are copied their value-sets shall contain default "-" values. + /// A copy shall keep its original owner + /// + Copy, + + /// + /// specifies that the on the is a "ctrl" Copy operation + /// + /// + /// If are copied their value-sets shall contain original values. + /// A copy shall have its owner set to the active one in the target destination. + /// + CopyKeepValuesChangeOwner, + + /// + /// specifies that the on the is a "dry" Copy operation + /// + /// + /// If are copied their value-sets shall contain default "-" values. + /// A copy shall have its owner set to the active one in the target destination. + /// + CopyDefaultValuesChangeOwner, + + /// + /// specifies that the on the is a "ctrl + shift" Copy operation + /// + /// + /// If are copied their value-sets shall contain the original values. + /// A copy shall keep its original owner + /// + CopyKeepValues + } +} diff --git a/CDP4Dal/Operations/PostOperation.cs b/CDP4DalCommon/Protocol/Operations/PostOperation.cs similarity index 80% rename from CDP4Dal/Operations/PostOperation.cs rename to CDP4DalCommon/Protocol/Operations/PostOperation.cs index 95d3eb250..36c9bd4d6 100644 --- a/CDP4Dal/Operations/PostOperation.cs +++ b/CDP4DalCommon/Protocol/Operations/PostOperation.cs @@ -1,78 +1,79 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2020 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4Dal.Operations -{ - using System.Collections.Generic; - using CDP4Common; - using CDP4Common.Dto; - using CDP4Common.DTO; - - /// - /// The abstract super class from which all POST operations derive. - /// - public abstract class PostOperation - { - /// - /// Initializes a new instance of the class - /// - protected PostOperation() - { - this.Delete = new List(); - this.Create = new List(); - this.Update = new List(); - this.Copy = new List(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - public abstract List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public abstract List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public abstract List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to copy. - /// - public abstract List Copy { get; set; } - - /// - /// Populate the current with the content based on the - /// provided - /// - /// - /// The that contains all the s that need to be - /// updated to the data-source - /// - public abstract void ConstructFromOperation(Operation operation); - } -} +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalCommon.Protocol.Operations +{ + using System.Collections.Generic; + + using CDP4Common; + using CDP4Common.Dto; + using CDP4Common.DTO; + + /// + /// The abstract super class from which all POST operations derive. + /// + public abstract class PostOperation + { + /// + /// Initializes a new instance of the class + /// + protected PostOperation() + { + this.Delete = new List(); + this.Create = new List(); + this.Update = new List(); + this.Copy = new List(); + } + + /// + /// Gets or sets the collection of DTOs to delete. + /// + public abstract List Delete { get; set; } + + /// + /// Gets or sets the collection of DTOs to create. + /// + public abstract List Create { get; set; } + + /// + /// Gets or sets the collection of DTOs to update. + /// + public abstract List Update { get; set; } + + /// + /// Gets or sets the collection of DTOs to copy. + /// + public abstract List Copy { get; set; } + + /// + /// Populate the current with the content based on the + /// provided + /// + /// + /// The that contains all the s that need to be + /// updated to the data-source + /// + public abstract void ConstructFromOperation(Operation operation); + } +} diff --git a/CDP4DalCommon/Tasks/CometTask.cs b/CDP4DalCommon/Protocol/Tasks/CometTask.cs similarity index 92% rename from CDP4DalCommon/Tasks/CometTask.cs rename to CDP4DalCommon/Protocol/Tasks/CometTask.cs index 057d4357a..1a617d2fa 100644 --- a/CDP4DalCommon/Tasks/CometTask.cs +++ b/CDP4DalCommon/Protocol/Tasks/CometTask.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -22,7 +22,7 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalCommon.Tasks +namespace CDP4DalCommon.Protocol.Tasks { using System; @@ -71,7 +71,7 @@ public CometTask() /// /// A value of -1 is returned when the task is still running or not completed with success /// - public readonly int Duration => this.ComputeDuration(); + public readonly int Duration => ComputeDuration(); /// /// Gets or sets the at which the was started @@ -107,12 +107,12 @@ public CometTask() /// The computated duration private readonly int ComputeDuration() { - if (!this.FinishedAt.HasValue || !this.StartedAt.HasValue) + if (!FinishedAt.HasValue || !StartedAt.HasValue) { return -1; } - var timeSpan = this.FinishedAt.Value - this.StartedAt.Value; + var timeSpan = FinishedAt.Value - StartedAt.Value; return (int)timeSpan.TotalSeconds; } } diff --git a/CDP4DalCommon/Tasks/StatusKind.cs b/CDP4DalCommon/Protocol/Tasks/StatusKind.cs similarity index 57% rename from CDP4DalCommon/Tasks/StatusKind.cs rename to CDP4DalCommon/Protocol/Tasks/StatusKind.cs index 9f903b951..31bb5596c 100644 --- a/CDP4DalCommon/Tasks/StatusKind.cs +++ b/CDP4DalCommon/Protocol/Tasks/StatusKind.cs @@ -1,29 +1,28 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // -// This file is part of CDP4-COMET Webservices Community Edition. -// The CDP4-COMET Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C. -// This is an auto-generated class. Any manual changes to this file will be overwritten! +// This file is part of CDP4-COMET SDK Community Edition // -// The CDP4-COMET Web Services Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The CDP4-COMET Web Services Community Edition is distributed in the hope that it will be useful, +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalCommon.Tasks +namespace CDP4DalCommon.Protocol.Tasks { using System.Threading.Tasks; @@ -52,4 +51,4 @@ public enum StatusKind /// CANCELLED } -} \ No newline at end of file +} diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj new file mode 100644 index 000000000..765eb528d --- /dev/null +++ b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj @@ -0,0 +1,44 @@ + + + + net47;net471;net472;net48;netstandard2.0;netstandard2.1 + RHEA System S.A. + latest + CDP4DalJsonSerializer Community Edition + 26.6.0 + JsonSerializer for the CDP4DalCommon types + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime + CDP4DalJsonSerializer-CE + true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + true + latest + + + + \ + true + + + \ + true + + + + + + + diff --git a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs new file mode 100644 index 000000000..5b9e6f660 --- /dev/null +++ b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs @@ -0,0 +1,86 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalJsonSerializer +{ + using System; + + using CDP4Common.MetaInfo; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer.JsonConverter; + + using CDP4JsonSerializer; + + /// + /// The is a that also supports (de)serialization of + /// + /// + public class Cdp4DalJsonSerializer : Cdp4JsonSerializer + { + /// + /// Asserts that the have to be ignored + /// + private readonly bool ignorePostOperationCopyProperty; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The meta Info Provider. + /// + /// + /// The supported version of the data-model + /// + /// Asserts that the have to be ignored + public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty = false) + { + this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; + + this.Initialize(metaInfoProvider, supportedVersion); + } + + /// + /// Initializes a new instance of the class. + /// + /// Asserts that the have to be ignored + public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty = false) + { + this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; + } + + /// + /// Initialize this instance with the required and supported + /// + /// The + /// The supported + public override void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) + { + base.Initialize(metaInfoProvider, supportedVersion); + + this.JsonSerializerOptions.Converters.Add(new PostOperationJsonConverter(this.ignorePostOperationCopyProperty)); + } + } +} diff --git a/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs b/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs new file mode 100644 index 000000000..1a7d927ff --- /dev/null +++ b/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalJsonSerializer.Extensions +{ + using System.Collections.Generic; + using System.Text.Json; + + using CDP4Common; + using CDP4Common.Dto; + using CDP4Common.DTO; + + using CDP4DalCommon.Protocol.Operations; + + /// + /// Extension class for + /// + public static class JsonElementExtensions + { + /// + /// Deserialize the content of the to the + /// + /// The + /// The that will receive new value properties + /// The + public static void DeserializePostOperation(this JsonElement element, PostOperation postOperation, JsonSerializerOptions serializerOptions) + { + if (element.TryGetProperty("_delete", out var deleteElement)) + { + postOperation.Delete = deleteElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_create", out var createElement)) + { + postOperation.Create = createElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_update", out var updateElement)) + { + postOperation.Update = updateElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_copy", out var copyElement)) + { + postOperation.Copy = copyElement.Deserialize>(serializerOptions); + } + } + } +} diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs new file mode 100644 index 000000000..90b70787c --- /dev/null +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -0,0 +1,150 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4DalJsonSerializer.JsonConverter +{ + using System; + using System.IO; + using System.Text.Json; + using System.Text.Json.Serialization; + + using CDP4Common.Polyfills; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer.Extensions; + + using NLog; + + /// + /// The for s + /// + public class PostOperationJsonConverter: JsonConverter + { + /// + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Asserts that the have to be ignored + /// + private readonly bool ignoreCopyProperty; + + /// + /// Initializes a new instance. + /// + /// Asserts that the have to be ignored + public PostOperationJsonConverter(bool ignoreCopyProperty = false) + { + this.ignoreCopyProperty = ignoreCopyProperty; + } + + /// + /// Override of the can convert type check. + /// + /// + /// The object type. + /// + /// + /// true if this converter is to be used. + /// + public override bool CanConvert(Type typeToConvert) + { + return typeof(PostOperation).QueryIsAssignableFrom(typeToConvert); + } + + /// Reads and converts the JSON to type . + /// The reader. + /// The type to convert. + /// An object that specifies serialization options to use. + /// The converted value. + public override PostOperation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) + { + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JObject type."); + } + + var initializedPostOperation = Activator.CreateInstance(typeToConvert); + + if (initializedPostOperation is not PostOperation postOperation) + { + Logger.Error($"The request Type {typeToConvert.Name} is not a PostOperation"); + throw new InvalidDataException($"The request Type {typeToConvert.Name} is not a PostOperation"); + } + + jsonElement?.DeserializePostOperation(postOperation, options); + return postOperation; + } + + /// Writes a specified value as JSON. + /// The writer to write to. + /// The value to convert to JSON. + /// An object that specifies serialization options to use. + public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WriteStartArray("_delete"); + + foreach (var toDelete in value.Delete) + { + JsonSerializer.Serialize(writer, toDelete, options); + } + + writer.WriteEndArray(); + writer.WriteStartArray("_create"); + + foreach (var toCreate in value.Create) + { + JsonSerializer.Serialize(writer, toCreate, options); + } + + writer.WriteEndArray(); + writer.WriteStartArray("_update"); + + foreach (var toUpdate in value.Update) + { + JsonSerializer.Serialize(writer, toUpdate, options); + } + + writer.WriteEndArray(); + + if (!this.ignoreCopyProperty) + { + writer.WriteStartArray("_copy"); + + foreach (var toCopy in value.Copy) + { + JsonSerializer.Serialize(writer, toCopy, options); + } + + writer.WriteEndArray(); + } + + writer.WriteEndObject(); + } + } +} diff --git a/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs b/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs index 00a37578a..38f469a04 100644 --- a/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs +++ b/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonFileDal.NetCore.Tests { @@ -32,6 +32,7 @@ namespace CDP4JsonFileDal.NetCore.Tests using System.Threading; using System.Threading.Tasks; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.DTO; using CDP4Common.Types; @@ -41,7 +42,7 @@ namespace CDP4JsonFileDal.NetCore.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4JsonFileDal; + using CDP4DalCommon.Protocol.Operations; using Moq; @@ -69,9 +70,6 @@ namespace CDP4JsonFileDal.NetCore.Tests using SampledFunctionParameterType = CDP4Common.SiteDirectoryData.SampledFunctionParameterType; using ElementDefinition = CDP4Common.EngineeringModelData.ElementDefinition; using Parameter = CDP4Common.EngineeringModelData.Parameter; - - using CDP4Common; - using OrganizationalParticipant = CDP4Common.SiteDirectoryData.OrganizationalParticipant; [TestFixture] @@ -530,7 +528,7 @@ public async Task VerifyWriteOfIncompatibleVersionFile() var domain = siteDirectory.Domain.First(); var model = new CDP4Common.EngineeringModelData.EngineeringModel(modelSetup.EngineeringModelIid, newSession.Assembler.Cache, newDal.Credentials.Uri) - { EngineeringModelSetup = modelSetup }; + { EngineeringModelSetup = modelSetup }; var iteration = new CDP4Common.EngineeringModelData.Iteration(this.iterationIid, newSession.Assembler.Cache, newDal.Credentials.Uri); @@ -590,7 +588,7 @@ public async Task VerifyWriteOfCompatibleVersionFile() var domain = siteDirectory.Domain.First(); var model = new CDP4Common.EngineeringModelData.EngineeringModel(modelSetup.EngineeringModelIid, newSession.Assembler.Cache, newDal.Credentials.Uri) - { EngineeringModelSetup = modelSetup }; + { EngineeringModelSetup = modelSetup }; var iteration = new CDP4Common.EngineeringModelData.Iteration(this.iterationIid, newSession.Assembler.Cache, newDal.Credentials.Uri); @@ -690,6 +688,7 @@ private void CreateBasicModel() iterationSetup.IterationIid = this.iterationIid; iterationSetupPoco.IterationIid = this.iterationIid; + // EngineeringModel this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.credentials.Uri); this.modelSetupId = Guid.NewGuid(); diff --git a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs index 406517edb..127a0018a 100644 --- a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs +++ b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonFileDal.Tests { @@ -32,6 +32,7 @@ namespace CDP4JsonFileDal.Tests using System.Threading; using System.Threading.Tasks; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.DTO; using CDP4Common.Types; @@ -41,7 +42,7 @@ namespace CDP4JsonFileDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4JsonFileDal; + using CDP4DalCommon.Protocol.Operations; using Moq; @@ -69,9 +70,6 @@ namespace CDP4JsonFileDal.Tests using SampledFunctionParameterType = CDP4Common.SiteDirectoryData.SampledFunctionParameterType; using ElementDefinition = CDP4Common.EngineeringModelData.ElementDefinition; using Parameter = CDP4Common.EngineeringModelData.Parameter; - - using CDP4Common; - using OrganizationalParticipant = CDP4Common.SiteDirectoryData.OrganizationalParticipant; [TestFixture] @@ -252,7 +250,7 @@ public async Task VerifyThatReadReturnsCorrectDTO() // General assertions for any kind of Thing we read Assert.That(readResult, Is.Not.Null); Assert.That(readResult.Count, Is.Not.EqualTo(1)); - + var iter1 = readResult.Single(d => d.ClassKind == ClassKind.Iteration); Assert.That(iter1.ClassKind, Is.EqualTo(iterObject.ClassKind)); Assert.That(iter1.Iid, Is.EqualTo(iterObject.Iid)); @@ -436,7 +434,7 @@ public void VerifyCtorWithVersionAndCopyright() Assert.That(this.dal.Serializer.RequestDataModelVersion.Major, Is.EqualTo(1)); Assert.That(this.dal.Serializer.RequestDataModelVersion.Minor, Is.EqualTo(0)); Assert.That(this.dal.Serializer.RequestDataModelVersion.Build, Is.EqualTo(0)); - + this.dal.UpdateExchangeFileHeader(new Person { ShortName = "admin" }); Assert.That(this.dal.FileHeader, Is.InstanceOf()); @@ -689,6 +687,7 @@ private void CreateBasicModel() iterationSetup.IterationIid = this.iterationIid; iterationSetupPoco.IterationIid = this.iterationIid; + // EngineeringModel this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.credentials.Uri); this.modelSetupId = Guid.NewGuid(); @@ -732,10 +731,10 @@ private void AddExtraThingsForExportFilteringTests() var elementDefinition2 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition2.ShortName = "ED2"; elementDefinition2.Owner = this.model.EngineeringModelSetup.ActiveDomain.First(); - + var elementDefinition3 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition3.ShortName = "ED3"; - + var elementDefinition4 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition4.ShortName = "ED4"; elementDefinition4.Owner = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.credentials.Uri); //Not in file @@ -754,7 +753,7 @@ private void AddExtraThingsForExportFilteringTests() elementDefinition1.Parameter.Add(sampledFunctionParameter1); elementDefinition2.Parameter.Add(sampledFunctionParameter2); - + this.iterationPoco.Element.Add(elementDefinition1); this.iterationPoco.Element.Add(elementDefinition2); this.iterationPoco.Element.Add(elementDefinition3); @@ -770,7 +769,7 @@ private void AddExtraThingsForExportFilteringTests() parameterOverride.ValueSet.Add(new CDP4Common.EngineeringModelData.ParameterOverrideValueSet(Guid.NewGuid(), this.cache, this.credentials.Uri)); parameterOverride.ValueSet.First().ParameterValueSet = sampledFunctionParameter2.ValueSet.First(); elementUsage.ParameterOverride.Add(parameterOverride); - + elementDefinition1.ContainedElement.Add(elementUsage); var citation = new CDP4Common.CommonData.Citation(Guid.NewGuid(), this.cache, this.credentials.Uri); diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 45b8cec59..5023fcb9b 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -37,6 +37,7 @@ + diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index cde6bd66e..160486179 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2023 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The CDP4-COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -26,7 +26,6 @@ namespace CDP4JsonFileDal { using System; using System.Collections.Generic; - using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -46,11 +45,12 @@ namespace CDP4JsonFileDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; - using CDP4JsonFileDal.Json; + using CDP4DalJsonSerializer; - using CDP4JsonSerializer; + using CDP4JsonFileDal.Json; using Ionic.Zip; @@ -61,7 +61,6 @@ namespace CDP4JsonFileDal using Thing = CDP4Common.DTO.Thing; #if NETFRAMEWORK using System.ComponentModel.Composition; - using Newtonsoft.Json.Linq; #endif /// @@ -119,7 +118,7 @@ public class JsonFileDal : Dal /// public JsonFileDal() { - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); } /// @@ -138,7 +137,7 @@ public JsonFileDal(Version dalVersion) this.DalVersion = dalVersion; } - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); } /// @@ -157,9 +156,9 @@ public void UpdateExchangeFileHeader(Person person, string headerCopyright = nul } /// - /// Gets the + /// Gets the /// - public Cdp4JsonSerializer Serializer { get; private set; } + public Cdp4DalJsonSerializer Serializer { get; private set; } /// /// Gets the value indicating whether this is read only @@ -428,7 +427,7 @@ private IEnumerable RemoveUnlinkedMandatoryReferences(IEnumerable if (newThingsToRemove.Any()) { dtosToCheck = dtosToCheck.Where(x => !newThingsToRemove.Contains(x.Iid)).ToList(); - iidsToCheck.RemoveWhere(x=> newThingsToRemove.Contains(x)); + iidsToCheck.RemoveWhere(x => newThingsToRemove.Contains(x)); } else { diff --git a/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs index c9bc3fa87..c0e6b4916 100644 --- a/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs +++ b/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs @@ -1,32 +1,35 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests.Helper { using System; using System.Collections.Generic; + using System.IO; using System.Linq; + using System.Text.Json; + using System.Text.Json.Nodes; using CDP4Common.EngineeringModelData; using CDP4Common.MetaInfo; @@ -54,17 +57,23 @@ public void VerifyThatToJsonObjectOfOrderedItemReturnsJObject() object value = null; value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); propertyInfo.SetValue(orderedItem, value); + var stream = new MemoryStream(); + var utf8Writer = new Utf8JsonWriter(stream); + utf8Writer.WriteOrderedItem(orderedItem); + utf8Writer.Flush(); + stream.Position = 0; + var ut8Reader = new Utf8JsonReader(stream.ToArray()); - var jObject = SerializerHelper.ToJsonObject(orderedItem); - Assert.That(jObject.Properties().Count(), Is.EqualTo(3)); + var jObject = JsonObject.Create(JsonElement.ParseValue(ref ut8Reader)); + Assert.That(jObject.AsEnumerable().Count(), Is.EqualTo(3)); - var k = jObject.Property("k"); + jObject.TryGetPropertyValue("k", out var k); Assert.That(k, Is.Not.Null); - var v = jObject.Property("v"); + jObject.TryGetPropertyValue("v", out var v); Assert.That(v, Is.Not.Null); - var m = jObject.Property("m"); + jObject.TryGetPropertyValue("m", out var m); Assert.That(m, Is.Not.Null); } @@ -75,10 +84,11 @@ public void Verify_that_ParameterValueSet_is_serialized_and_deserialized() values.Add("this is a\nnewline"); values.Add("this is another\nnewline"); - var engineeringModel = new EngineeringModel {Iid = Guid.Parse("5643764e-f880-44bf-90ae-361f6661ceae")}; - var iteration = new Iteration {Iid = Guid.Parse("f744ae63-cf36-4cc4-8d76-e83edd44f6d2")}; - var elementDefinition = new ElementDefinition {Iid = Guid.Parse("f7f173ea-a742-42a5-81f1-59da2f470f16") }; - var parameter = new Parameter {Iid = Guid.Parse("607764de-7598-4be2-9a95-34669de273e3") }; + var engineeringModel = new EngineeringModel { Iid = Guid.Parse("5643764e-f880-44bf-90ae-361f6661ceae") }; + var iteration = new Iteration { Iid = Guid.Parse("f744ae63-cf36-4cc4-8d76-e83edd44f6d2") }; + var elementDefinition = new ElementDefinition { Iid = Guid.Parse("f7f173ea-a742-42a5-81f1-59da2f470f16") }; + var parameter = new Parameter { Iid = Guid.Parse("607764de-7598-4be2-9a95-34669de273e3") }; + var parameterValueSet = new ParameterValueSet { Iid = Guid.Parse("2366c662-b857-4313-85ea-51f9bf4588b1"), Manual = new ValueArray(values) @@ -171,7 +181,7 @@ the CEND sequence.If I need to use CEND I must escape one of the "; - private static readonly string[] TestStrings = + private static readonly string[] TestStrings = { "value with trailing spaces ", "value with trailing space ", diff --git a/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs index b3ca5daf5..9d64fe941 100644 --- a/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs +++ b/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests { @@ -41,8 +41,6 @@ namespace CDP4JsonSerializer.Tests using CDP4JsonSerializer.Tests.Helper; - using Newtonsoft.Json; - using NUnit.Framework; using Dto = CDP4Common.DTO; @@ -117,7 +115,7 @@ public void VerifyThatSerializeTimeCorrectly() using var reader = new StreamReader(memoryStream); var txt = reader.ReadToEnd(); - + Assert.That(txt, Does.Not.Contain("2222-02-02T22:22:22.222222")); Assert.That(txt, Does.Contain("2222-02-02T22:22:22.222Z")); } @@ -407,7 +405,7 @@ public void VerifyThatSerializationofOperationsWorks() result.Update.Single(x => x["Iid"].ToString() == subscriptionValueset.Iid.ToString()); var valueArray = (ValueArray)subscriptionValueSetClasslessDto["Manual"]; - + Assert.That(subscriptionValueSetClasslessDto["Iid"] is Guid, Is.True); Assert.That(subscriptionValueSetClasslessDto["ClassKind"] is ClassKind, Is.True); @@ -457,7 +455,7 @@ public void VerifyThatSerializeGiveSameInput() using var reader = new StreamReader(stream); var serializerResult = reader.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); - + Assert.That(response.Length, Is.EqualTo(serializerResult.Length)); } } @@ -498,7 +496,7 @@ public void VerifyThatValueSetDeserializationIsCorrectForStringThatRepresentEsca using var reader = new StreamReader(stream); var serializerResult = reader.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); - + Assert.That(serializedParameterValueSet.Length, Is.EqualTo(serializerResult.Length)); } } @@ -611,19 +609,16 @@ private class TestPostOperation /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public List Update { get; set; } /// diff --git a/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs b/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs index d7b6da8ce..3ea93b211 100644 --- a/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs +++ b/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs @@ -1,33 +1,36 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests.Helper { using System; using System.Collections.Generic; + using System.IO; using System.Linq; - + using System.Text.Json; + using System.Text.Json.Nodes; + using CDP4Common.EngineeringModelData; using CDP4Common.MetaInfo; using CDP4Common.Types; @@ -45,23 +48,30 @@ public void VerifyThatToJsonObjectOfOrderedItemReturnsJObject() { var uniqueIdentifier = Guid.NewGuid(); - var orderedItem = new OrderedItem {K = 1, V = uniqueIdentifier}; + var orderedItem = new OrderedItem { K = 1, V = uniqueIdentifier }; var propertyInfo = orderedItem.GetType().GetProperty("M"); - var value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); + object value = null; + value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); propertyInfo.SetValue(orderedItem, value); + var stream = new MemoryStream(); + var utf8Writer = new Utf8JsonWriter(stream); + utf8Writer.WriteOrderedItem(orderedItem); + utf8Writer.Flush(); + stream.Position = 0; + var ut8Reader = new Utf8JsonReader(stream.ToArray()); - var jObject = orderedItem.ToJsonObject(); - Assert.That(jObject.Properties().Count(), Is.EqualTo(3)); + var jObject = JsonObject.Create(JsonElement.ParseValue(ref ut8Reader)); + Assert.That(jObject.AsEnumerable().Count(), Is.EqualTo(3)); - var k = jObject.Property("k"); + jObject.TryGetPropertyValue("k", out var k); Assert.That(k, Is.Not.Null); - var v = jObject.Property("v"); + jObject.TryGetPropertyValue("v", out var v); Assert.That(v, Is.Not.Null); - var m = jObject.Property("m"); + jObject.TryGetPropertyValue("m", out var m); Assert.That(m, Is.Not.Null); } @@ -113,7 +123,7 @@ public void Verify_that_a_ValueArray_is_serialized_and_deserialized([ValueSource Assert.That(resultjson, Is.EqualTo(json), $"Json creation failed for string \"{input}\"."); } - + private const string JsonString = @"{""widget"": { ""debug"": ""on"", ""window"": { @@ -170,7 +180,7 @@ the CEND sequence.If I need to use CEND I must escape one of the "; - private static readonly string[] TestStrings = + private static readonly string[] TestStrings = { "value with trailing spaces ", "value with trailing space ", @@ -212,4 +222,4 @@ the CEND sequence.If I need to use CEND I must escape one of the JsonString }; } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs b/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs index 9ce52fa9f..6095cbbe1 100644 --- a/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs +++ b/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests { @@ -30,6 +30,7 @@ namespace CDP4JsonSerializer.Tests using System.Diagnostics; using System.IO; using System.Linq; + using System.Text.Json.Serialization; using CDP4Common; using CDP4Common.CommonData; @@ -41,8 +42,6 @@ namespace CDP4JsonSerializer.Tests using CDP4JsonSerializer.Tests.Helper; - using Newtonsoft.Json; - using NUnit.Framework; using Dto = CDP4Common.DTO; @@ -170,7 +169,7 @@ public void VerifyThatValueArrayAreSerializedCorrectly() var txt = reader.ReadToEnd(); // output: "manual":"[\"123\",\"abc\"]" - Assert.That(txt, Does.Contain("\"manual\":\"[\\\"123\\\",\\\"abc\\\"]\"")); + Assert.That(txt, Does.Contain("\"manual\":\"[\\\"123\\\",\\\"abc\\\"]\"")); } } } @@ -412,9 +411,10 @@ public void VerifyThatSerializationofOperationsWorks() // necessary memoryStream.Position = 0; - + var content = new StreamReader(memoryStream).ReadToEnd(); + memoryStream.Position = 0; var result = this.serializer.Deserialize(memoryStream); - + Assert.That(result.Delete.Count, Is.EqualTo(1)); Assert.That(result.Create.Count, Is.EqualTo(1)); Assert.That(result.Update.Count, Is.EqualTo(2)); @@ -617,19 +617,19 @@ private class TestPostOperation /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] + [JsonPropertyName("_delete")] public List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] + [JsonPropertyName("_create")] public List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] + [JsonPropertyName("_update")] public List Update { get; set; } /// diff --git a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs b/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs index 12dbafe1f..ed7bacaa7 100644 --- a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs +++ b/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs @@ -1,51 +1,50 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests.Cdp4PostOperation { using System.Collections.Generic; + using System.Text.Json.Serialization; using CDP4Common; using CDP4Common.DTO; - using Newtonsoft.Json; - /// /// A CdpPostOperation class used for testing purposes /// public class CdpPostOperation { - [JsonProperty("_delete")] + [JsonPropertyName("_delete")] public List Delete { get; set; } - [JsonProperty("_create")] + [JsonPropertyName("_create")] public List Create { get; set; } - [JsonProperty("_update")] + [JsonPropertyName("_update")] public List Update { get; set; } - [JsonProperty("_copy")] + [JsonPropertyName("_copy")] public List Copy { get; set; } } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index 12f4beb26..7e7c2b211 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,151 +28,287 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actionItem = new CDP4Common.DTO.ActionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actionee"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actionItem.Actionee = jObject["actionee"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var actionItem = new CDP4Common.DTO.ActionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actionee"u8, out var actioneeProperty)) { - actionItem.Actor = jObject["actor"].ToObject(); + if(actioneeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale actionee property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Actionee = actioneeProperty.GetGuid(); + } } - if (!jObject["approvedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - actionItem.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + actionItem.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - actionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - actionItem.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + actionItem.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - actionItem.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["closeOutDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutDate"u8, out var closeOutDateProperty)) { - actionItem.CloseOutDate = jObject["closeOutDate"].ToObject(); + if(closeOutDateProperty.ValueKind == JsonValueKind.Null) + { + actionItem.CloseOutDate = null; + } + else + { + actionItem.CloseOutDate = closeOutDateProperty.GetDateTime(); + } } - if (!jObject["closeOutStatement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutStatement"u8, out var closeOutStatementProperty)) { - actionItem.CloseOutStatement = jObject["closeOutStatement"].ToObject(); + if(closeOutStatementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale closeOutStatement property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CloseOutStatement = closeOutStatementProperty.GetString(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - actionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - actionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - actionItem.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + actionItem.Discussion.Add(element.GetGuid()); + } } - if (!jObject["dueDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dueDate"u8, out var dueDateProperty)) { - actionItem.DueDate = jObject["dueDate"].ToObject(); + if(dueDateProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale dueDate property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.DueDate = dueDateProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - actionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actionItem.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - actionItem.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + actionItem.PrimaryAnnotatedThing = null; + } + else + { + actionItem.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - actionItem.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + actionItem.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - actionItem.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - actionItem.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + actionItem.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - actionItem.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - actionItem.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Title = titleProperty.GetString(); + } } return actionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index ca3dbc24e..9ff4be99c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,112 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty) && actualStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ActualState.AddRange(jObject["actualState"].ToObject>()); + foreach(var element in actualStateProperty.EnumerateArray()) + { + actualFiniteStateList.ActualState.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actualFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty)) { - actualFiniteStateList.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToOrderedItemCollection()); + actualFiniteStateList.PossibleFiniteStateList.AddRange(possibleFiniteStateListProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index 11f02c17f..152686837 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - actualFiniteState.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale kind property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.Kind = ActualFiniteStateKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty) && possibleStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.PossibleState.AddRange(jObject["possibleState"].ToObject>()); + foreach(var element in possibleStateProperty.EnumerateArray()) + { + actualFiniteState.PossibleState.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index 601c35831..56a4aacfd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AliasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Alias FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var alias = new CDP4Common.DTO.Alias(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AliasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - alias.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var alias = new CDP4Common.DTO.Alias(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - alias.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the alias {id} is null", alias.Iid); + } + else + { + alias.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + alias.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + alias.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isSynonym"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isSynonym"u8, out var isSynonymProperty)) { - alias.IsSynonym = jObject["isSynonym"].ToObject(); + if(isSynonymProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isSynonym property of the alias {id} is null", alias.Iid); + } + else + { + alias.IsSynonym = isSynonymProperty.GetBoolean(); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - alias.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the alias {id} is null", alias.Iid); + } + else + { + alias.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - alias.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the alias {id} is null", alias.Iid); + } + else + { + alias.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - alias.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the alias {id} is null", alias.Iid); + } + else + { + alias.ThingPreference = thingPreferenceProperty.GetString(); + } } return alias; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index ea01ef656..1ea4589f2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AndExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.AndExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.AndExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var andExpression = new CDP4Common.DTO.AndExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AndExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - andExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var andExpression = new CDP4Common.DTO.AndExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + andExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + andExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - andExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - andExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + andExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - andExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return andExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index 25487112d..a7223295e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ApprovalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Approval FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var approval = new CDP4Common.DTO.Approval(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ApprovalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - approval.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var approval = new CDP4Common.DTO.Approval(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - approval.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the approval {id} is null", approval.Iid); + } + else + { + approval.Author = authorProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - approval.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the approval {id} is null", approval.Iid); + } + else + { + approval.Classification = AnnotationApprovalKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - approval.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the approval {id} is null", approval.Iid); + } + else + { + approval.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - approval.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + approval.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + approval.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - approval.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the approval {id} is null", approval.Iid); + } + else + { + approval.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - approval.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - approval.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the approval {id} is null", approval.Iid); + } + else + { + approval.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - approval.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the approval {id} is null", approval.Iid); + } + else + { + approval.ThingPreference = thingPreferenceProperty.GetString(); + } } return approval; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index 80af4fa45..c159b1b55 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,116 +28,193 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ArrayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ArrayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - arrayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + arrayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + arrayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - arrayParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + arrayParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + arrayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dimension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dimension"u8, out var dimensionProperty)) { - arrayParameterType.Dimension.AddRange(jObject["dimension"].ToOrderedItemCollection()); + arrayParameterType.Dimension.AddRange(dimensionProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + arrayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + arrayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + arrayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - arrayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - arrayParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isFinalized property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["isTensor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isTensor"u8, out var isTensorProperty)) { - arrayParameterType.IsTensor = jObject["isTensor"].ToObject(); + if(isTensorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isTensor property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsTensor = isTensorProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - arrayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - arrayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - arrayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - arrayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - arrayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return arrayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index 12f8f7613..0e4aa3f37 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryNote = new CDP4Common.DTO.BinaryNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["caption"].IsNullOrEmpty()) + var binaryNote = new CDP4Common.DTO.BinaryNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("caption"u8, out var captionProperty)) { - binaryNote.Caption = jObject["caption"].ToObject(); + if(captionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale caption property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Caption = captionProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryNote.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - binaryNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - binaryNote.FileType = jObject["fileType"].ToObject(); + if(fileTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale fileType property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.FileType = fileTypeProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index abbc98d50..2f4ce317a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + binaryRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - binaryRelationship.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale source property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - binaryRelationship.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale target property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index a98ccc863..d27b9cbf7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,199 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - binaryRelationshipRule.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipRuleResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["definition"].IsNullOrEmpty()) + var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + binaryRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + binaryRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["forwardRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ForwardRelationshipName = jObject["forwardRelationshipName"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("forwardRelationshipName"u8, out var forwardRelationshipNameProperty)) { - binaryRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + if(forwardRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale forwardRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ForwardRelationshipName = forwardRelationshipNameProperty.GetString(); + } } - if (!jObject["inverseRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.InverseRelationshipName = jObject["inverseRelationshipName"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + binaryRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("inverseRelationshipName"u8, out var inverseRelationshipNameProperty)) { - binaryRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(inverseRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale inverseRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.InverseRelationshipName = inverseRelationshipNameProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - binaryRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationshipRule.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - binaryRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale relationshipCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["sourceCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryRelationshipRule.SourceCategory = jObject["sourceCategory"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["targetCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceCategory"u8, out var sourceCategoryProperty)) { - binaryRelationshipRule.TargetCategory = jObject["targetCategory"].ToObject(); - } + if(sourceCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale sourceCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.SourceCategory = sourceCategoryProperty.GetGuid(); + } + } + + if (jsonElement.TryGetProperty("targetCategory"u8, out var targetCategoryProperty)) + { + if(targetCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale targetCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.TargetCategory = targetCategoryProperty.GetGuid(); + } + } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index de63bcbbd..02a849837 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BookResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Book FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var book = new CDP4Common.DTO.Book(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BookResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - book.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var book = new CDP4Common.DTO.Book(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - book.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + book.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - book.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the book {id} is null", book.Iid); + } + else + { + book.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + book.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + book.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - book.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the book {id} is null", book.Iid); + } + else + { + book.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - book.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the book {id} is null", book.Iid); + } + else + { + book.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - book.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the book {id} is null", book.Iid); + } + else + { + book.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["section"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("section"u8, out var sectionProperty)) { - book.Section.AddRange(jObject["section"].ToOrderedItemCollection()); + book.Section.AddRange(sectionProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - book.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the book {id} is null", book.Iid); + } + else + { + book.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - book.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the book {id} is null", book.Iid); + } + else + { + book.ThingPreference = thingPreferenceProperty.GetString(); + } } return book; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index 369e4a6f4..78a4acd3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BooleanParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BooleanParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - booleanParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + booleanParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + booleanParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + booleanParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + booleanParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + booleanParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + booleanParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - booleanParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - booleanParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - booleanParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - booleanParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - booleanParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - booleanParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return booleanParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index ce8640827..040a11bd0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BoundsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Bounds FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var bounds = new CDP4Common.DTO.Bounds(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BoundsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - bounds.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var bounds = new CDP4Common.DTO.Bounds(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + bounds.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + bounds.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["height"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("height"u8, out var heightProperty)) { - bounds.Height = jObject["height"].ToObject(); + if(heightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale height property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Height = heightProperty.GetSingle(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - bounds.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - bounds.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - bounds.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["width"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("width"u8, out var widthProperty)) { - bounds.Width = jObject["width"].ToObject(); + if(widthProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale width property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Width = widthProperty.GetSingle(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - bounds.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale x property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - bounds.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale y property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Y = yProperty.GetSingle(); + } } return bounds; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index 474cbd6c6..e86891285 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BuiltInRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - builtInRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BuiltInRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - builtInRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - builtInRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + builtInRuleVerification.ExecutedOn = null; + } + else + { + builtInRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - builtInRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isActive property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - builtInRuleVerification.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - builtInRuleVerification.Status = jObject["status"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - builtInRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - builtInRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return builtInRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index 660ad2650..babc936ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,167 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CategoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Category FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var category = new CDP4Common.DTO.Category(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CategoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - category.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var category = new CDP4Common.DTO.Category(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - category.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + category.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - category.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + category.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + category.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + category.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - category.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + category.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isAbstract"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) { - category.IsAbstract = jObject["isAbstract"].ToObject(); + if(isAbstractProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isAbstract property of the category {id} is null", category.Iid); + } + else + { + category.IsAbstract = isAbstractProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - category.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the category {id} is null", category.Iid); + } + else + { + category.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - category.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the category {id} is null", category.Iid); + } + else + { + category.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - category.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the category {id} is null", category.Iid); + } + else + { + category.Name = nameProperty.GetString(); + } } - if (!jObject["permissibleClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("permissibleClass"u8, out var permissibleClassProperty) && permissibleClassProperty.ValueKind != JsonValueKind.Null) { - category.PermissibleClass.AddRange(jObject["permissibleClass"].ToObject>()); + foreach(var element in permissibleClassProperty.EnumerateArray()) + { + category.PermissibleClass.Add(ClassKindDeserializer.Deserialize(element)); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - category.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the category {id} is null", category.Iid); + } + else + { + category.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["superCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("superCategory"u8, out var superCategoryProperty) && superCategoryProperty.ValueKind != JsonValueKind.Null) { - category.SuperCategory.AddRange(jObject["superCategory"].ToObject>()); + foreach(var element in superCategoryProperty.EnumerateArray()) + { + category.SuperCategory.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - category.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the category {id} is null", category.Iid); + } + else + { + category.ThingPreference = thingPreferenceProperty.GetString(); + } } return category; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index 3bb8d36cc..fae894ee8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeProposalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeProposal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeProposal = new CDP4Common.DTO.ChangeProposal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeProposalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeProposal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeProposal = new CDP4Common.DTO.ChangeProposal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeProposal.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeProposal.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeProposal.Category.Add(element.GetGuid()); + } } - if (!jObject["changeRequest"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeRequest"u8, out var changeRequestProperty)) { - changeProposal.ChangeRequest = jObject["changeRequest"].ToObject(); + if(changeRequestProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale changeRequest property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ChangeRequest = changeRequestProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeProposal.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeProposal.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeProposal.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeProposal.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeProposal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeProposal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeProposal.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeProposal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeProposal.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeProposal.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeProposal.PrimaryAnnotatedThing = null; + } + else + { + changeProposal.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeProposal.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeProposal.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeProposal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeProposal.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeProposal.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeProposal.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeProposal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeProposal.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Title = titleProperty.GetString(); + } } return changeProposal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index 39d40aea3..e7cd93b16 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeRequestResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeRequest FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeRequest = new CDP4Common.DTO.ChangeRequest(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeRequestResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeRequest.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeRequest = new CDP4Common.DTO.ChangeRequest(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeRequest.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeRequest.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeRequest.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeRequest.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeRequest.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeRequest.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeRequest.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeRequest.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeRequest.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeRequest.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeRequest.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeRequest.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeRequest.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeRequest.PrimaryAnnotatedThing = null; + } + else + { + changeRequest.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeRequest.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeRequest.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeRequest.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeRequest.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeRequest.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeRequest.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeRequest.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeRequest.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Title = titleProperty.GetString(); + } } return changeRequest; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index f26d8aa6f..7d4b2e3bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CitationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Citation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var citation = new CDP4Common.DTO.Citation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CitationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - citation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var citation = new CDP4Common.DTO.Citation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + citation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + citation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isAdaptation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAdaptation"u8, out var isAdaptationProperty)) { - citation.IsAdaptation = jObject["isAdaptation"].ToObject(); + if(isAdaptationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isAdaptation property of the citation {id} is null", citation.Iid); + } + else + { + citation.IsAdaptation = isAdaptationProperty.GetBoolean(); + } } - if (!jObject["location"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("location"u8, out var locationProperty)) { - citation.Location = jObject["location"].ToObject(); + if(locationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale location property of the citation {id} is null", citation.Iid); + } + else + { + citation.Location = locationProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - citation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the citation {id} is null", citation.Iid); + } + else + { + citation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["remark"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("remark"u8, out var remarkProperty)) { - citation.Remark = jObject["remark"].ToObject(); + if(remarkProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale remark property of the citation {id} is null", citation.Iid); + } + else + { + citation.Remark = remarkProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - citation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the citation {id} is null", citation.Iid); + } + else + { + citation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - citation.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale source property of the citation {id} is null", citation.Iid); + } + else + { + citation.Source = sourceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - citation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the citation {id} is null", citation.Iid); + } + else + { + citation.ThingPreference = thingPreferenceProperty.GetString(); + } } return citation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index 187ad15ca..10ad217a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ColorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Color FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var color = new CDP4Common.DTO.Color(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ColorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - color.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["blue"].IsNullOrEmpty()) + var color = new CDP4Common.DTO.Color(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("blue"u8, out var blueProperty)) { - color.Blue = jObject["blue"].ToObject(); + if(blueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale blue property of the color {id} is null", color.Iid); + } + else + { + color.Blue = blueProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + color.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + color.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["green"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("green"u8, out var greenProperty)) { - color.Green = jObject["green"].ToObject(); + if(greenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale green property of the color {id} is null", color.Iid); + } + else + { + color.Green = greenProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - color.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the color {id} is null", color.Iid); + } + else + { + color.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - color.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the color {id} is null", color.Iid); + } + else + { + color.Name = nameProperty.GetString(); + } } - if (!jObject["red"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("red"u8, out var redProperty)) { - color.Red = jObject["red"].ToObject(); + if(redProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale red property of the color {id} is null", color.Iid); + } + else + { + color.Red = redProperty.GetInt32(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - color.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the color {id} is null", color.Iid); + } + else + { + color.ThingPreference = thingPreferenceProperty.GetString(); + } } return color; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index c908c9a85..0b18fb310 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,131 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CommonFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CommonFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CommonFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - commonFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - commonFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + commonFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + commonFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + commonFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + commonFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - commonFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - commonFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - commonFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - commonFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return commonFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index 6eb3f16bf..565b835c6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,176 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CompoundParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CompoundParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - compoundParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + compoundParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + compoundParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - compoundParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + compoundParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + compoundParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + compoundParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + compoundParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + compoundParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - compoundParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - compoundParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isFinalized property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - compoundParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - compoundParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - compoundParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - compoundParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - compoundParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return compoundParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index 282c63007..c3219160a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,175 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ConstantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Constant FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var constant = new CDP4Common.DTO.Constant(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - constant.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ConstantResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - constant.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var constant = new CDP4Common.DTO.Constant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - constant.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + constant.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - constant.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + constant.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + constant.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + constant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - constant.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + constant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - constant.IsDeprecated = jObject["isDeprecated"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + constant.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - constant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the constant {id} is null", constant.Iid); + } + else + { + constant.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - constant.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the constant {id} is null", constant.Iid); + } + else + { + constant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - constant.ParameterType = jObject["parameterType"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the constant {id} is null", constant.Iid); + } + else + { + constant.Name = nameProperty.GetString(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - constant.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the constant {id} is null", constant.Iid); + } + else + { + constant.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - constant.ShortName = jObject["shortName"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + constant.Scale = null; + } + else + { + constant.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - constant.ThingPreference = jObject["thingPreference"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the constant {id} is null", constant.Iid); + } + else + { + constant.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the constant {id} is null", constant.Iid); + } + else + { + constant.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - constant.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + constant.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return constant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index dffd7f9fb..b4aa0b635 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ContractChangeNoticeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ContractChangeNoticeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - contractChangeNotice.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + contractChangeNotice.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - contractChangeNotice.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + contractChangeNotice.Category.Add(element.GetGuid()); + } } - if (!jObject["changeProposal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeProposal"u8, out var changeProposalProperty)) { - contractChangeNotice.ChangeProposal = jObject["changeProposal"].ToObject(); + if(changeProposalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale changeProposal property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ChangeProposal = changeProposalProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - contractChangeNotice.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - contractChangeNotice.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - contractChangeNotice.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + contractChangeNotice.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - contractChangeNotice.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - contractChangeNotice.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - contractChangeNotice.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - contractChangeNotice.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + contractChangeNotice.PrimaryAnnotatedThing = null; + } + else + { + contractChangeNotice.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + contractChangeNotice.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - contractChangeNotice.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + contractChangeNotice.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - contractChangeNotice.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - contractChangeNotice.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - contractChangeNotice.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Title = titleProperty.GetString(); + } } return contractChangeNotice; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index b9a51d584..e479477f8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,141 +28,263 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CyclicRatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CyclicRatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - cyclicRatioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + cyclicRatioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + cyclicRatioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + cyclicRatioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - cyclicRatioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - cyclicRatioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMaximumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - cyclicRatioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMinimumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + cyclicRatioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - cyclicRatioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maximumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - cyclicRatioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minimumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - cyclicRatioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["modulus"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modulus"u8, out var modulusProperty)) { - cyclicRatioScale.Modulus = jObject["modulus"].ToObject(); + if(modulusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modulus property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Modulus = modulusProperty.GetString(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - cyclicRatioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - cyclicRatioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale negativeValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - cyclicRatioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale numberSet property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - cyclicRatioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale positiveValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - cyclicRatioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - cyclicRatioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - cyclicRatioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + cyclicRatioScale.ValueDefinition.Add(element.GetGuid()); + } } return cyclicRatioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index 964d4dc10..cedfd804c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateParameterType = new CDP4Common.DTO.DateParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateParameterType = new CDP4Common.DTO.DateParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index 5e06047d3..397201bff 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateTimeParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateTimeParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateTimeParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateTimeParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateTimeParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateTimeParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateTimeParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateTimeParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateTimeParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateTimeParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateTimeParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateTimeParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateTimeParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateTimeParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index 525a3d409..840efd27d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DecompositionRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DecompositionRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DecompositionRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - decompositionRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + decompositionRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["containedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedCategory"u8, out var containedCategoryProperty) && containedCategoryProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ContainedCategory.AddRange(jObject["containedCategory"].ToObject>()); + foreach(var element in containedCategoryProperty.EnumerateArray()) + { + decompositionRule.ContainedCategory.Add(element.GetGuid()); + } } - if (!jObject["containingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containingCategory"u8, out var containingCategoryProperty)) { - decompositionRule.ContainingCategory = jObject["containingCategory"].ToObject(); + if(containingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale containingCategory property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ContainingCategory = containingCategoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + decompositionRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + decompositionRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + decompositionRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + decompositionRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - decompositionRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxContained"u8, out var maxContainedProperty)) { - decompositionRule.MaxContained = jObject["maxContained"].ToObject(); + if(maxContainedProperty.ValueKind == JsonValueKind.Null) + { + decompositionRule.MaxContained = null; + } + else + { + decompositionRule.MaxContained = maxContainedProperty.GetInt32(); + } } - if (!jObject["minContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minContained"u8, out var minContainedProperty)) { - decompositionRule.MinContained = jObject["minContained"].ToObject(); + if(minContainedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minContained property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.MinContained = minContainedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - decompositionRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - decompositionRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - decompositionRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - decompositionRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return decompositionRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 4fe20140d..9a90885b1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,121 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Definition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var definition = new CDP4Common.DTO.Definition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - definition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["citation"].IsNullOrEmpty()) + var definition = new CDP4Common.DTO.Definition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("citation"u8, out var citationProperty) && citationProperty.ValueKind != JsonValueKind.Null) { - definition.Citation.AddRange(jObject["citation"].ToObject>()); + foreach(var element in citationProperty.EnumerateArray()) + { + definition.Citation.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - definition.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the definition {id} is null", definition.Iid); + } + else + { + definition.Content = contentProperty.GetString(); + } } - if (!jObject["example"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("example"u8, out var exampleProperty)) { - definition.Example.AddRange(jObject["example"].ToOrderedItemCollection()); + definition.Example.AddRange(exampleProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + definition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + definition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - definition.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the definition {id} is null", definition.Iid); + } + else + { + definition.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - definition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the definition {id} is null", definition.Iid); + } + else + { + definition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - definition.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + definition.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - definition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the definition {id} is null", definition.Iid); + } + else + { + definition.ThingPreference = thingPreferenceProperty.GetString(); + } } return definition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index 26f651b42..b424f62a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dependentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - dependentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + dependentParameterTypeAssignment.MeasurementScale = null; + } + else + { + dependentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dependentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - dependentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dependentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return dependentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index 83c4c7fdd..351ed6f2a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,116 +28,196 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + derivedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - derivedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale defaultScale property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + derivedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - derivedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale quantityDimensionSymbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["quantityKindFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKindFactor"u8, out var quantityKindFactorProperty)) { - derivedQuantityKind.QuantityKindFactor.AddRange(jObject["quantityKindFactor"].ToOrderedItemCollection()); + derivedQuantityKind.QuantityKindFactor.AddRange(quantityKindFactorProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - derivedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return derivedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index 3a55dcad1..843692006 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unitFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitFactor"u8, out var unitFactorProperty)) { - derivedUnit.UnitFactor.AddRange(jObject["unitFactor"].ToOrderedItemCollection()); + derivedUnit.UnitFactor.AddRange(unitFactorProperty.ToOrderedItemCollection()); } return derivedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index a42335a3a..eb1f7514d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramCanvasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramCanvasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramCanvas.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramCanvas.Bounds.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - diagramCanvas.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramCanvas.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramCanvas.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramCanvas.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramCanvas.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramCanvas.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramCanvas.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramCanvas; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index 1ade8376c..c5e8aff11 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,168 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramEdgeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramEdge FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramEdgeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramEdge.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramEdge.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramEdge.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.DepictedThing = null; + } + else + { + diagramEdge.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramEdge.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramEdge.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramEdge.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramEdge.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramEdge.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramEdge.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Name = nameProperty.GetString(); + } } - if (!jObject["point"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("point"u8, out var pointProperty)) { - diagramEdge.Point.AddRange(jObject["point"].ToOrderedItemCollection()); + diagramEdge.Point.AddRange(pointProperty.ToOrderedItemCollection()); } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramEdge.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.SharedStyle = null; + } + else + { + diagramEdge.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - diagramEdge.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale source property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - diagramEdge.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale target property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramEdge.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramEdge; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index 7569ca9ba..be0d77768 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramObjectResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramObject FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramObject = new CDP4Common.DTO.DiagramObject(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramObjectResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramObject.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramObject = new CDP4Common.DTO.DiagramObject(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramObject.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramObject.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramObject.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.DepictedThing = null; + } + else + { + diagramObject.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramObject.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramObject.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["documentation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("documentation"u8, out var documentationProperty)) { - diagramObject.Documentation = jObject["documentation"].ToObject(); + if(documentationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale documentation property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Documentation = documentationProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramObject.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramObject.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramObject.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramObject.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramObject.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramObject.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Name = nameProperty.GetString(); + } } - if (!jObject["resolution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("resolution"u8, out var resolutionProperty)) { - diagramObject.Resolution = jObject["resolution"].ToObject(); + if(resolutionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale resolution property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Resolution = resolutionProperty.GetSingle(); + } } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramObject.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.SharedStyle = null; + } + else + { + diagramObject.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramObject.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramObject; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index 86f060cae..5c95e266f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - domainFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + domainFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + domainFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["isHidden"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isHidden"u8, out var isHiddenProperty)) { - domainFileStore.IsHidden = jObject["isHidden"].ToObject(); + if(isHiddenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isHidden property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.IsHidden = isHiddenProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - domainFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index e8e10c972..842036389 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertiseGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertiseGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertiseGroup.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertiseGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertiseGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertiseGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertiseGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertiseGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index 4a967c2e1..06cf55214 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertise.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertise.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + domainOfExpertise.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertise.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertise.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertise.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertise.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertise.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertise.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertise.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertise; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs index 9ff256d51..2ba7c5a7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs @@ -2,17 +2,16 @@ // // Copyright (c) 2015-2023 RHEA System S.A. // -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Jaime Bernar // -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! +// This file is part of CDP4-SDK Community Edition // -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// The CDP4-SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. @@ -30,11 +29,10 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - - using CDP4Common.DTO; - - using Newtonsoft.Json.Linq; - + using System.Text.Json; + + using CDP4Common.DTO; + /// /// Utility class that is responsible for instantiating a /// @@ -43,7 +41,7 @@ public static class DtoFactory /// /// The type to Constructor map /// - private static readonly Dictionary> DtoConstructorMap = new Dictionary> + private static readonly Dictionary> DtoConstructorMap = new() { { "ActionItem", ActionItemResolver.FromJsonObject }, { "ActualFiniteState", ActualFiniteStateResolver.FromJsonObject }, @@ -194,20 +192,20 @@ public static class DtoFactory }; /// - /// Instantiates a new from a + /// Instantiates a new from a /// - /// The containing the data + /// The containing the data /// The to instantiate - public static Thing ToDto(this JObject dataObject) + public static Thing ToDto(this JsonElement dataObject) { - var classKind = dataObject["classKind"].ToString(); - Func constructor; - if (!DtoConstructorMap.TryGetValue(classKind, out constructor)) + var classKind = dataObject.GetProperty("classKind").ToString(); + + if(!DtoConstructorMap.TryGetValue(classKind, out var constructor)) { throw new InvalidOperationException($"The dto resolver was not found for {classKind}"); } - return constructor(dataObject); + return constructor.Invoke(dataObject); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index 27df1b5d1..91c5c81bb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,116 +28,187 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementDefinition.Category.Add(element.GetGuid()); + } } - if (!jObject["containedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedElement"u8, out var containedElementProperty) && containedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ContainedElement.AddRange(jObject["containedElement"].ToObject>()); + foreach(var element in containedElementProperty.EnumerateArray()) + { + elementDefinition.ContainedElement.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + elementDefinition.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementDefinition.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty) && parameterProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Parameter.AddRange(jObject["parameter"].ToObject>()); + foreach(var element in parameterProperty.EnumerateArray()) + { + elementDefinition.Parameter.Add(element.GetGuid()); + } } - if (!jObject["parameterGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterGroup"u8, out var parameterGroupProperty) && parameterGroupProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ParameterGroup.AddRange(jObject["parameterGroup"].ToObject>()); + foreach(var element in parameterGroupProperty.EnumerateArray()) + { + elementDefinition.ParameterGroup.Add(element.GetGuid()); + } } - if (!jObject["referencedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedElement"u8, out var referencedElementProperty) && referencedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ReferencedElement.AddRange(jObject["referencedElement"].ToObject>()); + foreach(var element in referencedElementProperty.EnumerateArray()) + { + elementDefinition.ReferencedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index fcd002488..8406d81e3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,187 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementUsageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementUsage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementUsage = new CDP4Common.DTO.ElementUsage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementUsageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementUsage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementUsage = new CDP4Common.DTO.ElementUsage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementUsage.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementUsage.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementUsage.Definition.Add(element.GetGuid()); + } } - if (!jObject["elementDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("elementDefinition"u8, out var elementDefinitionProperty)) { - elementUsage.ElementDefinition = jObject["elementDefinition"].ToObject(); + if(elementDefinitionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale elementDefinition property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ElementDefinition = elementDefinitionProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementUsage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementUsage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + elementUsage.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementUsage.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementUsage.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interfaceEnd"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("interfaceEnd"u8, out var interfaceEndProperty)) { - elementUsage.InterfaceEnd = jObject["interfaceEnd"].ToObject(); + if(interfaceEndProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale interfaceEnd property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.InterfaceEnd = InterfaceEndKindDeserializer.Deserialize(interfaceEndProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementUsage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementUsage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementUsage.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterOverride"u8, out var parameterOverrideProperty) && parameterOverrideProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ParameterOverride.AddRange(jObject["parameterOverride"].ToObject>()); + foreach(var element in parameterOverrideProperty.EnumerateArray()) + { + elementUsage.ParameterOverride.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementUsage.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementUsage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementUsage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index f9ad1c2fe..de0fbc233 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EmailAddressResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EmailAddress FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var emailAddress = new CDP4Common.DTO.EmailAddress(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EmailAddressResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - emailAddress.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var emailAddress = new CDP4Common.DTO.EmailAddress(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + emailAddress.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + emailAddress.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - emailAddress.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - emailAddress.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - emailAddress.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty)) { - emailAddress.VcardType = jObject["vcardType"].ToObject(); + if(vcardTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.VcardType = VcardEmailAddressKindDeserializer.Deserialize(vcardTypeProperty); + } } return emailAddress; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index 46728856a..3cd779c8f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - engineeringModelDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataDiscussionItem.ReplyTo = null; + } + else + { + engineeringModelDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index 409a21d17..d49355db9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataNote.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + engineeringModelDataNote.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - engineeringModelDataNote.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataNote.PrimaryAnnotatedThing = null; + } + else + { + engineeringModelDataNote.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + engineeringModelDataNote.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index 10f480a5e..f4f0ac12d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,148 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModel FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModel.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["book"].IsNullOrEmpty()) + var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("book"u8, out var bookProperty)) { - engineeringModel.Book.AddRange(jObject["book"].ToOrderedItemCollection()); + engineeringModel.Book.AddRange(bookProperty.ToOrderedItemCollection()); } - if (!jObject["commonFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("commonFileStore"u8, out var commonFileStoreProperty) && commonFileStoreProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.CommonFileStore.AddRange(jObject["commonFileStore"].ToObject>()); + foreach(var element in commonFileStoreProperty.EnumerateArray()) + { + engineeringModel.CommonFileStore.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelSetup"u8, out var engineeringModelSetupProperty)) { - engineeringModel.EngineeringModelSetup = jObject["engineeringModelSetup"].ToObject(); + if(engineeringModelSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale engineeringModelSetup property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.EngineeringModelSetup = engineeringModelSetupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModel.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModel.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["genericNote"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("genericNote"u8, out var genericNoteProperty) && genericNoteProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.GenericNote.AddRange(jObject["genericNote"].ToObject>()); + foreach(var element in genericNoteProperty.EnumerateArray()) + { + engineeringModel.GenericNote.Add(element.GetGuid()); + } } - if (!jObject["iteration"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iteration"u8, out var iterationProperty) && iterationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.Iteration.AddRange(jObject["iteration"].ToObject>()); + foreach(var element in iterationProperty.EnumerateArray()) + { + engineeringModel.Iteration.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - engineeringModel.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale lastModifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + engineeringModel.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["modellingAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modellingAnnotation"u8, out var modellingAnnotationProperty) && modellingAnnotationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ModellingAnnotation.AddRange(jObject["modellingAnnotation"].ToObject>()); + foreach(var element in modellingAnnotationProperty.EnumerateArray()) + { + engineeringModel.ModellingAnnotation.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModel.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModel.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModel; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index 64efc44ba..a0a05f287 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,131 +28,227 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["activeDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelSetup.ActiveDomain.AddRange(jObject["activeDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("activeDomain"u8, out var activeDomainProperty) && activeDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Actor = jObject["actor"].ToObject(); + foreach(var element in activeDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ActiveDomain.Add(element.GetGuid()); + } } - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + engineeringModelSetup.Alias.Add(element.GetGuid()); + } } - if (!jObject["defaultOrganizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOrganizationalParticipant"u8, out var defaultOrganizationalParticipantProperty)) { - engineeringModelSetup.DefaultOrganizationalParticipant = jObject["defaultOrganizationalParticipant"].ToObject(); + if(defaultOrganizationalParticipantProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.DefaultOrganizationalParticipant = null; + } + else + { + engineeringModelSetup.DefaultOrganizationalParticipant = defaultOrganizationalParticipantProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + engineeringModelSetup.Definition.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelIid"u8, out var engineeringModelIidProperty)) { - engineeringModelSetup.EngineeringModelIid = jObject["engineeringModelIid"].ToObject(); + if(engineeringModelIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale engineeringModelIid property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.EngineeringModelIid = engineeringModelIidProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + engineeringModelSetup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty) && iterationSetupProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.IterationSetup.AddRange(jObject["iterationSetup"].ToObject>()); + foreach(var element in iterationSetupProperty.EnumerateArray()) + { + engineeringModelSetup.IterationSetup.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - engineeringModelSetup.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale kind property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Kind = EngineeringModelKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - engineeringModelSetup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + engineeringModelSetup.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["participant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participant"u8, out var participantProperty) && participantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Participant.AddRange(jObject["participant"].ToObject>()); + foreach(var element in participantProperty.EnumerateArray()) + { + engineeringModelSetup.Participant.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty) && requiredRdlProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.RequiredRdl.AddRange(jObject["requiredRdl"].ToObject>()); + foreach(var element in requiredRdlProperty.EnumerateArray()) + { + engineeringModelSetup.RequiredRdl.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - engineeringModelSetup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceEngineeringModelSetupIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceEngineeringModelSetupIid"u8, out var sourceEngineeringModelSetupIidProperty)) { - engineeringModelSetup.SourceEngineeringModelSetupIid = jObject["sourceEngineeringModelSetupIid"].ToObject(); + if(sourceEngineeringModelSetupIidProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.SourceEngineeringModelSetupIid = null; + } + else + { + engineeringModelSetup.SourceEngineeringModelSetupIid = sourceEngineeringModelSetupIidProperty.GetGuid(); + } } - if (!jObject["studyPhase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("studyPhase"u8, out var studyPhaseProperty)) { - engineeringModelSetup.StudyPhase = jObject["studyPhase"].ToObject(); + if(studyPhaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale studyPhase property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.StudyPhase = StudyPhaseKindDeserializer.Deserialize(studyPhaseProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index 54ddc8d5b..6059bd7aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,176 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["allowMultiSelect"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("allowMultiSelect"u8, out var allowMultiSelectProperty)) { - enumerationParameterType.AllowMultiSelect = jObject["allowMultiSelect"].ToObject(); + if(allowMultiSelectProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale allowMultiSelect property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.AllowMultiSelect = allowMultiSelectProperty.GetBoolean(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + enumerationParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - enumerationParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - enumerationParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty)) { - enumerationParameterType.ValueDefinition.AddRange(jObject["valueDefinition"].ToOrderedItemCollection()); + enumerationParameterType.ValueDefinition.AddRange(valueDefinitionProperty.ToOrderedItemCollection()); } return enumerationParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index 5b475059b..b0db8660e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return enumerationValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index 9708214d8..62d37fbb2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExclusiveOrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExclusiveOrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - exclusiveOrExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - exclusiveOrExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + exclusiveOrExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - exclusiveOrExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return exclusiveOrExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index f168262a2..242f14aac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExternalIdentifierMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExternalIdentifierMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - externalIdentifierMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["correspondence"].IsNullOrEmpty()) + var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("correspondence"u8, out var correspondenceProperty) && correspondenceProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.Correspondence.AddRange(jObject["correspondence"].ToObject>()); + foreach(var element in correspondenceProperty.EnumerateArray()) + { + externalIdentifierMap.Correspondence.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalFormat"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalFormat"u8, out var externalFormatProperty)) { - externalIdentifierMap.ExternalFormat = jObject["externalFormat"].ToObject(); + if(externalFormatProperty.ValueKind == JsonValueKind.Null) + { + externalIdentifierMap.ExternalFormat = null; + } + else + { + externalIdentifierMap.ExternalFormat = externalFormatProperty.GetGuid(); + } } - if (!jObject["externalModelName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalModelName"u8, out var externalModelNameProperty)) { - externalIdentifierMap.ExternalModelName = jObject["externalModelName"].ToObject(); + if(externalModelNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale externalModelName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalModelName = externalModelNameProperty.GetString(); + } } - if (!jObject["externalToolName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolName"u8, out var externalToolNameProperty)) { - externalIdentifierMap.ExternalToolName = jObject["externalToolName"].ToObject(); + if(externalToolNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale externalToolName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolName = externalToolNameProperty.GetString(); + } } - if (!jObject["externalToolVersion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolVersion"u8, out var externalToolVersionProperty)) { - externalIdentifierMap.ExternalToolVersion = jObject["externalToolVersion"].ToObject(); + if(externalToolVersionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale externalToolVersion property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolVersion = externalToolVersionProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - externalIdentifierMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - externalIdentifierMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - externalIdentifierMap.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - externalIdentifierMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ThingPreference = thingPreferenceProperty.GetString(); + } } return externalIdentifierMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index f3256bef9..d7f52a5db 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.File FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var file = new CDP4Common.DTO.File(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - file.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var file = new CDP4Common.DTO.File(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - file.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + file.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + file.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + file.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileRevision"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileRevision"u8, out var fileRevisionProperty) && fileRevisionProperty.ValueKind != JsonValueKind.Null) { - file.FileRevision.AddRange(jObject["fileRevision"].ToObject>()); + foreach(var element in fileRevisionProperty.EnumerateArray()) + { + file.FileRevision.Add(element.GetGuid()); + } } - if (!jObject["lockedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lockedBy"u8, out var lockedByProperty)) { - file.LockedBy = jObject["lockedBy"].ToObject(); + if(lockedByProperty.ValueKind == JsonValueKind.Null) + { + file.LockedBy = null; + } + else + { + file.LockedBy = lockedByProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - file.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the file {id} is null", file.Iid); + } + else + { + file.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - file.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the file {id} is null", file.Iid); + } + else + { + file.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - file.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the file {id} is null", file.Iid); + } + else + { + file.ThingPreference = thingPreferenceProperty.GetString(); + } } return file; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index 972ac1e0a..e7dc7b9bc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileRevisionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileRevision FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileRevision = new CDP4Common.DTO.FileRevision(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileRevisionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileRevision.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var fileRevision = new CDP4Common.DTO.FileRevision(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - fileRevision.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + fileRevision.ContainingFolder = null; + } + else + { + fileRevision.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["contentHash"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("contentHash"u8, out var contentHashProperty)) { - fileRevision.ContentHash = jObject["contentHash"].ToObject(); + if(contentHashProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale contentHash property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ContentHash = contentHashProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - fileRevision.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - fileRevision.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale creator property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileRevision.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileRevision.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - fileRevision.FileType.AddRange(jObject["fileType"].ToOrderedItemCollection()); + fileRevision.FileType.AddRange(fileTypeProperty.ToOrderedItemCollection()); } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileRevision.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileRevision.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileRevision.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileRevision; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 323d805cf..15a415fa9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileType = new CDP4Common.DTO.FileType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var fileType = new CDP4Common.DTO.FileType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - fileType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + fileType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - fileType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + fileType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - fileType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + fileType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["extension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("extension"u8, out var extensionProperty)) { - fileType.Extension = jObject["extension"].ToObject(); + if(extensionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale extension property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Extension = extensionProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - fileType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + fileType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - fileType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - fileType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index 4fbc9d09a..61957f20b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FolderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Folder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var folder = new CDP4Common.DTO.Folder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FolderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - folder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var folder = new CDP4Common.DTO.Folder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - folder.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + folder.ContainingFolder = null; + } + else + { + folder.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - folder.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - folder.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale creator property of the folder {id} is null", folder.Iid); + } + else + { + folder.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + folder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + folder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - folder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - folder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the folder {id} is null", folder.Iid); + } + else + { + folder.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - folder.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the folder {id} is null", folder.Iid); + } + else + { + folder.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - folder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the folder {id} is null", folder.Iid); + } + else + { + folder.ThingPreference = thingPreferenceProperty.GetString(); + } } return folder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 2032ed59d..0b62a5f65 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GlossaryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Glossary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var glossary = new CDP4Common.DTO.Glossary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GlossaryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - glossary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var glossary = new CDP4Common.DTO.Glossary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - glossary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + glossary.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - glossary.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + glossary.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - glossary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + glossary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + glossary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + glossary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - glossary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + glossary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - glossary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - glossary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - glossary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - glossary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - glossary.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + glossary.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - glossary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ThingPreference = thingPreferenceProperty.GetString(); + } } return glossary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index b1a0e8b94..add132c03 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GoalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Goal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var goal = new CDP4Common.DTO.Goal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GoalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - goal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var goal = new CDP4Common.DTO.Goal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - goal.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + goal.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - goal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + goal.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - goal.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + goal.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + goal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + goal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - goal.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + goal.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - goal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the goal {id} is null", goal.Iid); + } + else + { + goal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - goal.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the goal {id} is null", goal.Iid); + } + else + { + goal.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - goal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the goal {id} is null", goal.Iid); + } + else + { + goal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - goal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the goal {id} is null", goal.Iid); + } + else + { + goal.ThingPreference = thingPreferenceProperty.GetString(); + } } return goal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index 05bb163bf..2a47f983c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class HyperLinkResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.HyperLink FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var hyperLink = new CDP4Common.DTO.HyperLink(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the HyperLinkResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - hyperLink.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var hyperLink = new CDP4Common.DTO.HyperLink(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - hyperLink.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + hyperLink.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + hyperLink.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - hyperLink.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - hyperLink.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - hyperLink.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["uri"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("uri"u8, out var uriProperty)) { - hyperLink.Uri = jObject["uri"].ToObject(); + if(uriProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale uri property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Uri = uriProperty.GetString(); + } } return hyperLink; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index 3cffd872f..dc573c684 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IdCorrespondenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IdCorrespondenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - idCorrespondence.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + idCorrespondence.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + idCorrespondence.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalId"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalId"u8, out var externalIdProperty)) { - idCorrespondence.ExternalId = jObject["externalId"].ToObject(); + if(externalIdProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale externalId property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ExternalId = externalIdProperty.GetString(); + } } - if (!jObject["internalThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("internalThing"u8, out var internalThingProperty)) { - idCorrespondence.InternalThing = jObject["internalThing"].ToObject(); + if(internalThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale internalThing property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.InternalThing = internalThingProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - idCorrespondence.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - idCorrespondence.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ThingPreference = thingPreferenceProperty.GetString(); + } } return idCorrespondence; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index 21471938e..2d8f77bb6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IndependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IndependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - independentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - independentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + independentParameterTypeAssignment.MeasurementScale = null; + } + else + { + independentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - independentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - independentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - independentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return independentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index 7b96dc691..ca2a5d4c8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IntervalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IntervalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var intervalScale = new CDP4Common.DTO.IntervalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IntervalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - intervalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var intervalScale = new CDP4Common.DTO.IntervalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + intervalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + intervalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + intervalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + intervalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - intervalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + intervalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - intervalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - intervalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMaximumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - intervalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMinimumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - intervalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + intervalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - intervalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maximumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - intervalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minimumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - intervalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - intervalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - intervalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale negativeValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - intervalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale numberSet property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - intervalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale positiveValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - intervalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - intervalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - intervalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + intervalScale.ValueDefinition.Add(element.GetGuid()); + } } return intervalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index 72117f3b8..ffc947b3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,161 +28,260 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Iteration FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iteration = new CDP4Common.DTO.Iteration(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iteration.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualFiniteStateList"].IsNullOrEmpty()) + var iteration = new CDP4Common.DTO.Iteration(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualFiniteStateList"u8, out var actualFiniteStateListProperty) && actualFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.ActualFiniteStateList.AddRange(jObject["actualFiniteStateList"].ToObject>()); + foreach(var element in actualFiniteStateListProperty.EnumerateArray()) + { + iteration.ActualFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["defaultOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOption"u8, out var defaultOptionProperty)) { - iteration.DefaultOption = jObject["defaultOption"].ToObject(); + if(defaultOptionProperty.ValueKind == JsonValueKind.Null) + { + iteration.DefaultOption = null; + } + else + { + iteration.DefaultOption = defaultOptionProperty.GetGuid(); + } } - if (!jObject["diagramCanvas"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramCanvas"u8, out var diagramCanvasProperty) && diagramCanvasProperty.ValueKind != JsonValueKind.Null) { - iteration.DiagramCanvas.AddRange(jObject["diagramCanvas"].ToObject>()); + foreach(var element in diagramCanvasProperty.EnumerateArray()) + { + iteration.DiagramCanvas.Add(element.GetGuid()); + } } - if (!jObject["domainFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainFileStore"u8, out var domainFileStoreProperty) && domainFileStoreProperty.ValueKind != JsonValueKind.Null) { - iteration.DomainFileStore.AddRange(jObject["domainFileStore"].ToObject>()); + foreach(var element in domainFileStoreProperty.EnumerateArray()) + { + iteration.DomainFileStore.Add(element.GetGuid()); + } } - if (!jObject["element"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("element"u8, out var elementProperty) && elementProperty.ValueKind != JsonValueKind.Null) { - iteration.Element.AddRange(jObject["element"].ToObject>()); + foreach(var element in elementProperty.EnumerateArray()) + { + iteration.Element.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iteration.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iteration.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalIdentifierMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalIdentifierMap"u8, out var externalIdentifierMapProperty) && externalIdentifierMapProperty.ValueKind != JsonValueKind.Null) { - iteration.ExternalIdentifierMap.AddRange(jObject["externalIdentifierMap"].ToObject>()); + foreach(var element in externalIdentifierMapProperty.EnumerateArray()) + { + iteration.ExternalIdentifierMap.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - iteration.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + iteration.Goal.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty)) { - iteration.IterationSetup = jObject["iterationSetup"].ToObject(); + if(iterationSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale iterationSetup property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.IterationSetup = iterationSetupProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iteration.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["option"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("option"u8, out var optionProperty)) { - iteration.Option.AddRange(jObject["option"].ToOrderedItemCollection()); + iteration.Option.AddRange(optionProperty.ToOrderedItemCollection()); } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty) && possibleFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToObject>()); + foreach(var element in possibleFiniteStateListProperty.EnumerateArray()) + { + iteration.PossibleFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["publication"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publication"u8, out var publicationProperty) && publicationProperty.ValueKind != JsonValueKind.Null) { - iteration.Publication.AddRange(jObject["publication"].ToObject>()); + foreach(var element in publicationProperty.EnumerateArray()) + { + iteration.Publication.Add(element.GetGuid()); + } } - if (!jObject["relationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationship"u8, out var relationshipProperty) && relationshipProperty.ValueKind != JsonValueKind.Null) { - iteration.Relationship.AddRange(jObject["relationship"].ToObject>()); + foreach(var element in relationshipProperty.EnumerateArray()) + { + iteration.Relationship.Add(element.GetGuid()); + } } - if (!jObject["requirementsSpecification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirementsSpecification"u8, out var requirementsSpecificationProperty) && requirementsSpecificationProperty.ValueKind != JsonValueKind.Null) { - iteration.RequirementsSpecification.AddRange(jObject["requirementsSpecification"].ToObject>()); + foreach(var element in requirementsSpecificationProperty.EnumerateArray()) + { + iteration.RequirementsSpecification.Add(element.GetGuid()); + } } - if (!jObject["ruleVerificationList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerificationList"u8, out var ruleVerificationListProperty) && ruleVerificationListProperty.ValueKind != JsonValueKind.Null) { - iteration.RuleVerificationList.AddRange(jObject["ruleVerificationList"].ToObject>()); + foreach(var element in ruleVerificationListProperty.EnumerateArray()) + { + iteration.RuleVerificationList.Add(element.GetGuid()); + } } - if (!jObject["sharedDiagramStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedDiagramStyle"u8, out var sharedDiagramStyleProperty) && sharedDiagramStyleProperty.ValueKind != JsonValueKind.Null) { - iteration.SharedDiagramStyle.AddRange(jObject["sharedDiagramStyle"].ToObject>()); + foreach(var element in sharedDiagramStyleProperty.EnumerateArray()) + { + iteration.SharedDiagramStyle.Add(element.GetGuid()); + } } - if (!jObject["sourceIterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationIid"u8, out var sourceIterationIidProperty)) { - iteration.SourceIterationIid = jObject["sourceIterationIid"].ToObject(); + if(sourceIterationIidProperty.ValueKind == JsonValueKind.Null) + { + iteration.SourceIterationIid = null; + } + else + { + iteration.SourceIterationIid = sourceIterationIidProperty.GetGuid(); + } } - if (!jObject["stakeholder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholder"u8, out var stakeholderProperty) && stakeholderProperty.ValueKind != JsonValueKind.Null) { - iteration.Stakeholder.AddRange(jObject["stakeholder"].ToObject>()); + foreach(var element in stakeholderProperty.EnumerateArray()) + { + iteration.Stakeholder.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + iteration.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValueMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueMap"u8, out var stakeholderValueMapProperty) && stakeholderValueMapProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValueMap.AddRange(jObject["stakeholderValueMap"].ToObject>()); + foreach(var element in stakeholderValueMapProperty.EnumerateArray()) + { + iteration.StakeholderValueMap.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iteration.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topElement"u8, out var topElementProperty)) { - iteration.TopElement = jObject["topElement"].ToObject(); + if(topElementProperty.ValueKind == JsonValueKind.Null) + { + iteration.TopElement = null; + } + else + { + iteration.TopElement = topElementProperty.GetGuid(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - iteration.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + iteration.ValueGroup.Add(element.GetGuid()); + } } return iteration; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index 16ad67577..c8e8447f2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IterationSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iterationSetup = new CDP4Common.DTO.IterationSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iterationSetup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var iterationSetup = new CDP4Common.DTO.IterationSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - iterationSetup.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["description"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - iterationSetup.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale description property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iterationSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iterationSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["frozenOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("frozenOn"u8, out var frozenOnProperty)) { - iterationSetup.FrozenOn = jObject["frozenOn"].ToObject(); + if(frozenOnProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.FrozenOn = null; + } + else + { + iterationSetup.FrozenOn = frozenOnProperty.GetDateTime(); + } } - if (!jObject["isDeleted"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeleted"u8, out var isDeletedProperty)) { - iterationSetup.IsDeleted = jObject["isDeleted"].ToObject(); + if(isDeletedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeleted property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IsDeleted = isDeletedProperty.GetBoolean(); + } } - if (!jObject["iterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationIid"u8, out var iterationIidProperty)) { - iterationSetup.IterationIid = jObject["iterationIid"].ToObject(); + if(iterationIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale iterationIid property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationIid = iterationIidProperty.GetGuid(); + } } - if (!jObject["iterationNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationNumber"u8, out var iterationNumberProperty)) { - iterationSetup.IterationNumber = jObject["iterationNumber"].ToObject(); + if(iterationNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale iterationNumber property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationNumber = iterationNumberProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iterationSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["sourceIterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationSetup"u8, out var sourceIterationSetupProperty)) { - iterationSetup.SourceIterationSetup = jObject["sourceIterationSetup"].ToObject(); + if(sourceIterationSetupProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.SourceIterationSetup = null; + } + else + { + iterationSetup.SourceIterationSetup = sourceIterationSetupProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iterationSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return iterationSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index d2f22db3a..9cc1bca7b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LinearConversionUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LinearConversionUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - linearConversionUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + linearConversionUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - linearConversionUnit.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale conversionFactor property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + linearConversionUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + linearConversionUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - linearConversionUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - linearConversionUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - linearConversionUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.Name = nameProperty.GetString(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - linearConversionUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referenceUnit property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - linearConversionUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - linearConversionUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return linearConversionUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index 3f57890f2..b36348479 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,123 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogEntryChangelogItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogEntryChangelogItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logEntryChangelogItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty)) { - logEntryChangelogItem.AffectedItemIid = jObject["affectedItemIid"].ToObject(); + if(affectedItemIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale affectedItemIid property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.AffectedItemIid = affectedItemIidProperty.GetGuid(); + } } - if (!jObject["affectedReferenceIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedReferenceIid"u8, out var affectedReferenceIidProperty) && affectedReferenceIidProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.AffectedReferenceIid.AddRange(jObject["affectedReferenceIid"].ToObject>()); + foreach(var element in affectedReferenceIidProperty.EnumerateArray()) + { + logEntryChangelogItem.AffectedReferenceIid.Add(element.GetGuid()); + } } - if (!jObject["changeDescription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeDescription"u8, out var changeDescriptionProperty)) { - logEntryChangelogItem.ChangeDescription = jObject["changeDescription"].ToObject(); + if(changeDescriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale changeDescription property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangeDescription = changeDescriptionProperty.GetString(); + } } - if (!jObject["changelogKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changelogKind"u8, out var changelogKindProperty)) { - logEntryChangelogItem.ChangelogKind = jObject["changelogKind"].ToObject(); + if(changelogKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale changelogKind property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangelogKind = LogEntryChangelogItemKindDeserializer.Deserialize(changelogKindProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logEntryChangelogItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logEntryChangelogItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return logEntryChangelogItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index d4eeb426b..e7e3ecfe7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,161 +28,307 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogarithmicScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogarithmicScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logarithmicScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + logarithmicScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + logarithmicScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logarithmicScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logarithmicScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - logarithmicScale.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale exponent property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Exponent = exponentProperty.GetString(); + } } - if (!jObject["factor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("factor"u8, out var factorProperty)) { - logarithmicScale.Factor = jObject["factor"].ToObject(); + if(factorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale factor property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Factor = factorProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + logarithmicScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - logarithmicScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - logarithmicScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMaximumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - logarithmicScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMinimumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["logarithmBase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logarithmBase"u8, out var logarithmBaseProperty)) { - logarithmicScale.LogarithmBase = jObject["logarithmBase"].ToObject(); + if(logarithmBaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale logarithmBase property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.LogarithmBase = LogarithmBaseKindDeserializer.Deserialize(logarithmBaseProperty); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + logarithmicScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - logarithmicScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maximumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - logarithmicScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minimumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logarithmicScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - logarithmicScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - logarithmicScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale negativeValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - logarithmicScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale numberSet property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - logarithmicScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale positiveValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["referenceQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityKind"u8, out var referenceQuantityKindProperty)) { - logarithmicScale.ReferenceQuantityKind = jObject["referenceQuantityKind"].ToObject(); + if(referenceQuantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referenceQuantityKind property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ReferenceQuantityKind = referenceQuantityKindProperty.GetGuid(); + } } - if (!jObject["referenceQuantityValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityValue"u8, out var referenceQuantityValueProperty) && referenceQuantityValueProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ReferenceQuantityValue.AddRange(jObject["referenceQuantityValue"].ToObject>()); + foreach(var element in referenceQuantityValueProperty.EnumerateArray()) + { + logarithmicScale.ReferenceQuantityValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - logarithmicScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logarithmicScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - logarithmicScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + logarithmicScale.ValueDefinition.Add(element.GetGuid()); + } } return logarithmicScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index 6b91d30e1..dbb65b2f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MappingToReferenceScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MappingToReferenceScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - mappingToReferenceScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["dependentScaleValue"].IsNullOrEmpty()) + var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("dependentScaleValue"u8, out var dependentScaleValueProperty)) { - mappingToReferenceScale.DependentScaleValue = jObject["dependentScaleValue"].ToObject(); + if(dependentScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale dependentScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.DependentScaleValue = dependentScaleValueProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - mappingToReferenceScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referenceScaleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceScaleValue"u8, out var referenceScaleValueProperty)) { - mappingToReferenceScale.ReferenceScaleValue = jObject["referenceScaleValue"].ToObject(); + if(referenceScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referenceScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ReferenceScaleValue = referenceScaleValueProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - mappingToReferenceScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ThingPreference = thingPreferenceProperty.GetString(); + } } return mappingToReferenceScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index b50df3680..46817fdaf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,171 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - modelLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + modelLogEntry.Author = null; + } + else + { + modelLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + modelLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - modelLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - modelLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - modelLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - modelLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale level property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + modelLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return modelLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 3b5e3f44c..5490153a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,146 +28,232 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - modelReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + modelReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + modelReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - modelReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - modelReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + modelReferenceDataLibrary.RequiredRdl = null; + } + else + { + modelReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - modelReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + modelReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return modelReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index 498265b12..9f834b6c7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModellingThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModellingThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modellingThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modellingThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modellingThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modellingThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - modellingThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referencedRevisionNumber property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - modellingThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referencedThing property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modellingThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return modellingThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index 868696aa7..53831176a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + multiRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - multiRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + multiRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + multiRelationship.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index 923a693e7..8c980774c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationshipRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + multiRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + multiRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + multiRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - multiRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxRelated"u8, out var maxRelatedProperty)) { - multiRelationshipRule.MaxRelated = jObject["maxRelated"].ToObject(); + if(maxRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maxRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MaxRelated = maxRelatedProperty.GetInt32(); + } } - if (!jObject["minRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minRelated"u8, out var minRelatedProperty)) { - multiRelationshipRule.MinRelated = jObject["minRelated"].ToObject(); + if(minRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MinRelated = minRelatedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationshipRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["relatedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedCategory"u8, out var relatedCategoryProperty) && relatedCategoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.RelatedCategory.AddRange(jObject["relatedCategory"].ToObject>()); + foreach(var element in relatedCategoryProperty.EnumerateArray()) + { + multiRelationshipRule.RelatedCategory.Add(element.GetGuid()); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - multiRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale relationshipCategory property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - multiRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index 0d5981694..afc4b90e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NaturalLanguageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NaturalLanguageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - naturalLanguage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + naturalLanguage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + naturalLanguage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - naturalLanguage.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - naturalLanguage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - naturalLanguage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.Name = nameProperty.GetString(); + } } - if (!jObject["nativeName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nativeName"u8, out var nativeNameProperty)) { - naturalLanguage.NativeName = jObject["nativeName"].ToObject(); + if(nativeNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale nativeName property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.NativeName = nativeNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - naturalLanguage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ThingPreference = thingPreferenceProperty.GetString(); + } } return naturalLanguage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index 271d8daf5..d7eb62e54 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,116 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedElementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedElement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedElement = new CDP4Common.DTO.NestedElement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedElementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedElement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["elementUsage"].IsNullOrEmpty()) + var nestedElement = new CDP4Common.DTO.NestedElement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("elementUsage"u8, out var elementUsageProperty)) { - nestedElement.ElementUsage.AddRange(jObject["elementUsage"].ToOrderedItemCollection()); + nestedElement.ElementUsage.AddRange(elementUsageProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedElement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedElement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedElement.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isVolatile property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedElement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["nestedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedParameter"u8, out var nestedParameterProperty) && nestedParameterProperty.ValueKind != JsonValueKind.Null) { - nestedElement.NestedParameter.AddRange(jObject["nestedParameter"].ToObject>()); + foreach(var element in nestedParameterProperty.EnumerateArray()) + { + nestedElement.NestedParameter.Add(element.GetGuid()); + } } - if (!jObject["rootElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rootElement"u8, out var rootElementProperty)) { - nestedElement.RootElement = jObject["rootElement"].ToObject(); + if(rootElementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale rootElement property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.RootElement = rootElementProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedElement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedElement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index 985c18012..30c147689 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedParameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedParameter = new CDP4Common.DTO.NestedParameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedParameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var nestedParameter = new CDP4Common.DTO.NestedParameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - nestedParameter.ActualState = jObject["actualState"].ToObject(); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + nestedParameter.ActualState = null; + } + else + { + nestedParameter.ActualState = actualStateProperty.GetGuid(); + } } - if (!jObject["actualValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualValue"u8, out var actualValueProperty)) { - nestedParameter.ActualValue = jObject["actualValue"].ToObject(); + if(actualValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale actualValue property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ActualValue = actualValueProperty.GetString(); + } } - if (!jObject["associatedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("associatedParameter"u8, out var associatedParameterProperty)) { - nestedParameter.AssociatedParameter = jObject["associatedParameter"].ToObject(); + if(associatedParameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale associatedParameter property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.AssociatedParameter = associatedParameterProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedParameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedParameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - nestedParameter.Formula = jObject["formula"].ToObject(); + if(formulaProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale formula property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Formula = formulaProperty.GetString(); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedParameter.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isVolatile property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedParameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - nestedParameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedParameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedParameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index 6dbdea5c8..185f66df2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,61 +28,91 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NotExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NotExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var notExpression = new CDP4Common.DTO.NotExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NotExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - notExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var notExpression = new CDP4Common.DTO.NotExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + notExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + notExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - notExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty)) { - notExpression.Term = jObject["term"].ToObject(); + if(termProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale term property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.Term = termProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - notExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return notExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index e02366310..72dd27d06 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Option FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var option = new CDP4Common.DTO.Option(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - option.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var option = new CDP4Common.DTO.Option(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - option.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + option.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - option.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + option.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - option.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + option.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + option.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + option.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - option.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + option.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - option.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the option {id} is null", option.Iid); + } + else + { + option.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - option.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the option {id} is null", option.Iid); + } + else + { + option.Name = nameProperty.GetString(); + } } - if (!jObject["nestedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedElement"u8, out var nestedElementProperty) && nestedElementProperty.ValueKind != JsonValueKind.Null) { - option.NestedElement.AddRange(jObject["nestedElement"].ToObject>()); + foreach(var element in nestedElementProperty.EnumerateArray()) + { + option.NestedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - option.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the option {id} is null", option.Iid); + } + else + { + option.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - option.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the option {id} is null", option.Iid); + } + else + { + option.ThingPreference = thingPreferenceProperty.GetString(); + } } return option; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index d91451ac6..596b989ac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var orExpression = new CDP4Common.DTO.OrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - orExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var orExpression = new CDP4Common.DTO.OrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + orExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + orExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - orExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - orExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + orExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - orExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return orExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index 7d568acd9..fc3cb2148 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,141 +28,263 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrdinalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrdinalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrdinalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ordinalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ordinalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ordinalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ordinalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ordinalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ordinalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ordinalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ordinalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMaximumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ordinalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMinimumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ordinalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ordinalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maximumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ordinalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minimumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ordinalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ordinalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ordinalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale negativeValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ordinalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale numberSet property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ordinalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale positiveValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ordinalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ordinalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ordinalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["useShortNameValues"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("useShortNameValues"u8, out var useShortNameValuesProperty)) { - ordinalScale.UseShortNameValues = jObject["useShortNameValues"].ToObject(); + if(useShortNameValuesProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale useShortNameValues property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.UseShortNameValues = useShortNameValuesProperty.GetBoolean(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ordinalScale.ValueDefinition.Add(element.GetGuid()); + } } return ordinalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index fc82ad34b..2e50a992b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Organization FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organization = new CDP4Common.DTO.Organization(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organization.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organization = new CDP4Common.DTO.Organization(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organization.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organization.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - organization.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the organization {id} is null", organization.Iid); + } + else + { + organization.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organization.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the organization {id} is null", organization.Iid); + } + else + { + organization.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - organization.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the organization {id} is null", organization.Iid); + } + else + { + organization.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - organization.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the organization {id} is null", organization.Iid); + } + else + { + organization.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organization.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the organization {id} is null", organization.Iid); + } + else + { + organization.ThingPreference = thingPreferenceProperty.GetString(); + } } return organization; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index 5fa3f94d0..560cbfa06 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,61 +28,91 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationalParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationalParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organizationalParticipant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organizationalParticipant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - organizationalParticipant.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale organization property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organizationalParticipant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ThingPreference = thingPreferenceProperty.GetString(); + } } return organizationalParticipant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index fad8d6e57..a0c000fb4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,126 +28,243 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OwnedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OwnedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OwnedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ownedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ownedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ownedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - ownedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillColor = null; + } + else + { + ownedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - ownedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillOpacity = null; + } + else + { + ownedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - ownedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontBold = null; + } + else + { + ownedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - ownedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontColor = null; + } + else + { + ownedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - ownedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontItalic = null; + } + else + { + ownedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - ownedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale fontName property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - ownedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontSize = null; + } + else + { + ownedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - ownedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontStrokeThrough = null; + } + else + { + ownedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - ownedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontUnderline = null; + } + else + { + ownedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ownedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ownedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - ownedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeColor = null; + } + else + { + ownedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - ownedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeOpacity = null; + } + else + { + ownedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - ownedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeWidth = null; + } + else + { + ownedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ownedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + ownedStyle.UsedColor.Add(element.GetGuid()); + } } return ownedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index 66ccfbaaa..80415d1e6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Page FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var page = new CDP4Common.DTO.Page(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - page.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var page = new CDP4Common.DTO.Page(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - page.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + page.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - page.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the page {id} is null", page.Iid); + } + else + { + page.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + page.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + page.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - page.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the page {id} is null", page.Iid); + } + else + { + page.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - page.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the page {id} is null", page.Iid); + } + else + { + page.Name = nameProperty.GetString(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - page.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + page.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - page.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the page {id} is null", page.Iid); + } + else + { + page.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - page.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the page {id} is null", page.Iid); + } + else + { + page.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - page.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the page {id} is null", page.Iid); + } + else + { + page.ThingPreference = thingPreferenceProperty.GetString(); + } } return page; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 5d624fd21..97c0a8da7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingGroup"].IsNullOrEmpty()) + var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingGroup"u8, out var containingGroupProperty)) { - parameterGroup.ContainingGroup = jObject["containingGroup"].ToObject(); + if(containingGroupProperty.ValueKind == JsonValueKind.Null) + { + parameterGroup.ContainingGroup = null; + } + else + { + parameterGroup.ContainingGroup = containingGroupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index aabfdc220..1c54ce876 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverride FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverride.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverride.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverride.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverride.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterOverride.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty)) { - parameterOverride.Parameter = jObject["parameter"].ToObject(); + if(parameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameter property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Parameter = parameterProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameterOverride.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverride.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterOverride.ValueSet.Add(element.GetGuid()); + } } return parameterOverride; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index 99e36d494..431d85fbb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,124 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterOverrideValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterOverrideValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterOverrideValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["parameterValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverrideValueSet.ParameterValueSet = jObject["parameterValueSet"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValueSet"u8, out var parameterValueSetProperty)) { - parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(parameterValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterValueSet property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ParameterValueSet = parameterValueSetProperty.GetGuid(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverrideValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterOverrideValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale valueSwitch property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterOverrideValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index 124d4eaa6..f122ceab5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,203 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Parameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameter = new CDP4Common.DTO.Parameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["allowDifferentOwnerOfOverride"].IsNullOrEmpty()) + var parameter = new CDP4Common.DTO.Parameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("allowDifferentOwnerOfOverride"u8, out var allowDifferentOwnerOfOverrideProperty)) { - parameter.AllowDifferentOwnerOfOverride = jObject["allowDifferentOwnerOfOverride"].ToObject(); + if(allowDifferentOwnerOfOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale allowDifferentOwnerOfOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.AllowDifferentOwnerOfOverride = allowDifferentOwnerOfOverrideProperty.GetBoolean(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expectsOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expectsOverride"u8, out var expectsOverrideProperty)) { - parameter.ExpectsOverride = jObject["expectsOverride"].ToObject(); + if(expectsOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale expectsOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ExpectsOverride = expectsOverrideProperty.GetBoolean(); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - parameter.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + parameter.Group = null; + } + else + { + parameter.Group = groupProperty.GetGuid(); + } } - if (!jObject["isOptionDependent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isOptionDependent"u8, out var isOptionDependentProperty)) { - parameter.IsOptionDependent = jObject["isOptionDependent"].ToObject(); + if(isOptionDependentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isOptionDependent property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.IsOptionDependent = isOptionDependentProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameter.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameter.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameter.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["requestedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requestedBy"u8, out var requestedByProperty)) { - parameter.RequestedBy = jObject["requestedBy"].ToObject(); + if(requestedByProperty.ValueKind == JsonValueKind.Null) + { + parameter.RequestedBy = null; + } + else + { + parameter.RequestedBy = requestedByProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameter.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameter.Scale = null; + } + else + { + parameter.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["stateDependence"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stateDependence"u8, out var stateDependenceProperty)) { - parameter.StateDependence = jObject["stateDependence"].ToObject(); + if(stateDependenceProperty.ValueKind == JsonValueKind.Null) + { + parameter.StateDependence = null; + } + else + { + parameter.StateDependence = stateDependenceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameter.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameter.ValueSet.Add(element.GetGuid()); + } } return parameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index eced250bd..98f8d7966 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscription.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscription.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscription.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscription.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterSubscription.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscription.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterSubscription.ValueSet.Add(element.GetGuid()); + } } return parameterSubscription; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index f7e18d00d..e96359edd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterSubscriptionValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscriptionValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscriptionValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) + { + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedPerson.Add(element.GetGuid()); + } + } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscriptionValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["subscribedValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("subscribedValueSet"u8, out var subscribedValueSetProperty)) { - parameterSubscriptionValueSet.SubscribedValueSet = jObject["subscribedValueSet"].ToObject(); + if(subscribedValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale subscribedValueSet property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.SubscribedValueSet = subscribedValueSetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscriptionValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterSubscriptionValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale valueSwitch property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterSubscriptionValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index 6dbd6614b..46dd2f162 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterTypeComponentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterTypeComponentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterTypeComponent.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterTypeComponent.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameterTypeComponent.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameterTypeComponent.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameterTypeComponent.Scale = null; + } + else + { + parameterTypeComponent.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterTypeComponent.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterTypeComponent.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterTypeComponent; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index 9a7cc5016..c90526ee6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["actualOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterValueSet.ActualOption = jObject["actualOption"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualOption"u8, out var actualOptionProperty)) { - parameterValueSet.ActualState = jObject["actualState"].ToObject(); + if(actualOptionProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualOption = null; + } + else + { + parameterValueSet.ActualOption = actualOptionProperty.GetGuid(); + } } - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - parameterValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualState = null; + } + else + { + parameterValueSet.ActualState = actualStateProperty.GetGuid(); + } } - - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + parameterValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + parameterValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + parameterValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale valueSwitch property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index fdb38aa5b..8e2827fdf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterizedCategoryRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterizedCategoryRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterizedCategoryRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + parameterizedCategoryRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty)) { - parameterizedCategoryRule.Category = jObject["category"].ToObject(); + if(categoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale category property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Category = categoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + parameterizedCategoryRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + parameterizedCategoryRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - parameterizedCategoryRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterizedCategoryRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterizedCategoryRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + parameterizedCategoryRule.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterizedCategoryRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterizedCategoryRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterizedCategoryRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index 46f4fea29..f2d354a87 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParametricConstraintResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParametricConstraintResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parametricConstraint.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parametricConstraint.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parametricConstraint.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expression"u8, out var expressionProperty) && expressionProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.Expression.AddRange(jObject["expression"].ToObject>()); + foreach(var element in expressionProperty.EnumerateArray()) + { + parametricConstraint.Expression.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parametricConstraint.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parametricConstraint.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topExpression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topExpression"u8, out var topExpressionProperty)) { - parametricConstraint.TopExpression = jObject["topExpression"].ToObject(); + if(topExpressionProperty.ValueKind == JsonValueKind.Null) + { + parametricConstraint.TopExpression = null; + } + else + { + parametricConstraint.TopExpression = topExpressionProperty.GetGuid(); + } } return parametricConstraint; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index 217214995..fb6c00c08 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - participantPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale accessRight property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.AccessRight = ParticipantAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - participantPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale objectClass property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index c679f694c..0748cf6a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Participant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participant = new CDP4Common.DTO.Participant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["domain"].IsNullOrEmpty()) + var participant = new CDP4Common.DTO.Participant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - participant.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + participant.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - participant.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isActive property of the participant {id} is null", participant.Iid); + } + else + { + participant.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the participant {id} is null", participant.Iid); + } + else + { + participant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty)) { - participant.Person = jObject["person"].ToObject(); + if(personProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale person property of the participant {id} is null", participant.Iid); + } + else + { + participant.Person = personProperty.GetGuid(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - participant.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale role property of the participant {id} is null", participant.Iid); + } + else + { + participant.Role = roleProperty.GetGuid(); + } } - if (!jObject["selectedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("selectedDomain"u8, out var selectedDomainProperty)) { - participant.SelectedDomain = jObject["selectedDomain"].ToObject(); + if(selectedDomainProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale selectedDomain property of the participant {id} is null", participant.Iid); + } + else + { + participant.SelectedDomain = selectedDomainProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the participant {id} is null", participant.Iid); + } + else + { + participant.ThingPreference = thingPreferenceProperty.GetString(); + } } return participant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index d0ee24c56..d9f821a41 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantRole = new CDP4Common.DTO.ParticipantRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var participantRole = new CDP4Common.DTO.ParticipantRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - participantRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + participantRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - participantRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + participantRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - participantRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + participantRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - participantRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.Name = nameProperty.GetString(); + } } - if (!jObject["participantPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantPermission"u8, out var participantPermissionProperty) && participantPermissionProperty.ValueKind != JsonValueKind.Null) { - participantRole.ParticipantPermission.AddRange(jObject["participantPermission"].ToObject>()); + foreach(var element in participantPermissionProperty.EnumerateArray()) + { + participantRole.ParticipantPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - participantRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index 09be84327..e9bf0582a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personPermission = new CDP4Common.DTO.PersonPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var personPermission = new CDP4Common.DTO.PersonPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - personPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale accessRight property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.AccessRight = PersonAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - personPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale objectClass property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return personPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index b2e10cf76..e5c3c1b4b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,131 +28,247 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Person FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var person = new CDP4Common.DTO.Person(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - person.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["defaultDomain"].IsNullOrEmpty()) + var person = new CDP4Common.DTO.Person(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("defaultDomain"u8, out var defaultDomainProperty)) { - person.DefaultDomain = jObject["defaultDomain"].ToObject(); + if(defaultDomainProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultDomain = null; + } + else + { + person.DefaultDomain = defaultDomainProperty.GetGuid(); + } } - if (!jObject["defaultEmailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultEmailAddress"u8, out var defaultEmailAddressProperty)) { - person.DefaultEmailAddress = jObject["defaultEmailAddress"].ToObject(); + if(defaultEmailAddressProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultEmailAddress = null; + } + else + { + person.DefaultEmailAddress = defaultEmailAddressProperty.GetGuid(); + } } - if (!jObject["defaultTelephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultTelephoneNumber"u8, out var defaultTelephoneNumberProperty)) { - person.DefaultTelephoneNumber = jObject["defaultTelephoneNumber"].ToObject(); + if(defaultTelephoneNumberProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultTelephoneNumber = null; + } + else + { + person.DefaultTelephoneNumber = defaultTelephoneNumberProperty.GetGuid(); + } } - if (!jObject["emailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("emailAddress"u8, out var emailAddressProperty) && emailAddressProperty.ValueKind != JsonValueKind.Null) { - person.EmailAddress.AddRange(jObject["emailAddress"].ToObject>()); + foreach(var element in emailAddressProperty.EnumerateArray()) + { + person.EmailAddress.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + person.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + person.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["givenName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("givenName"u8, out var givenNameProperty)) { - person.GivenName = jObject["givenName"].ToObject(); + if(givenNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale givenName property of the person {id} is null", person.Iid); + } + else + { + person.GivenName = givenNameProperty.GetString(); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - person.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isActive property of the person {id} is null", person.Iid); + } + else + { + person.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - person.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the person {id} is null", person.Iid); + } + else + { + person.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - person.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the person {id} is null", person.Iid); + } + else + { + person.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - person.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + person.Organization = null; + } + else + { + person.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["organizationalUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalUnit"u8, out var organizationalUnitProperty)) { - person.OrganizationalUnit = jObject["organizationalUnit"].ToObject(); + if(organizationalUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale organizationalUnit property of the person {id} is null", person.Iid); + } + else + { + person.OrganizationalUnit = organizationalUnitProperty.GetString(); + } } - if (!jObject["password"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("password"u8, out var passwordProperty)) { - person.Password = jObject["password"].ToObject(); + if(passwordProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale password property of the person {id} is null", person.Iid); + } + else + { + person.Password = passwordProperty.GetString(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - person.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + person.Role = null; + } + else + { + person.Role = roleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - person.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the person {id} is null", person.Iid); + } + else + { + person.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["surname"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("surname"u8, out var surnameProperty)) { - person.Surname = jObject["surname"].ToObject(); + if(surnameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale surname property of the person {id} is null", person.Iid); + } + else + { + person.Surname = surnameProperty.GetString(); + } } - if (!jObject["telephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("telephoneNumber"u8, out var telephoneNumberProperty) && telephoneNumberProperty.ValueKind != JsonValueKind.Null) { - person.TelephoneNumber.AddRange(jObject["telephoneNumber"].ToObject>()); + foreach(var element in telephoneNumberProperty.EnumerateArray()) + { + person.TelephoneNumber.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - person.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the person {id} is null", person.Iid); + } + else + { + person.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["userPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("userPreference"u8, out var userPreferenceProperty) && userPreferenceProperty.ValueKind != JsonValueKind.Null) { - person.UserPreference.AddRange(jObject["userPreference"].ToObject>()); + foreach(var element in userPreferenceProperty.EnumerateArray()) + { + person.UserPreference.Add(element.GetGuid()); + } } return person; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index ba1463cb2..0b6afb333 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personRole = new CDP4Common.DTO.PersonRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var personRole = new CDP4Common.DTO.PersonRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - personRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + personRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - personRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + personRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - personRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + personRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - personRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.Name = nameProperty.GetString(); + } } - if (!jObject["personPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personPermission"u8, out var personPermissionProperty) && personPermissionProperty.ValueKind != JsonValueKind.Null) { - personRole.PersonPermission.AddRange(jObject["personPermission"].ToObject>()); + foreach(var element in personPermissionProperty.EnumerateArray()) + { + personRole.PersonPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - personRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return personRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index 181107f48..fb36ae541 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PointResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Point FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var point = new CDP4Common.DTO.Point(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PointResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - point.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var point = new CDP4Common.DTO.Point(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + point.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + point.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - point.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the point {id} is null", point.Iid); + } + else + { + point.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - point.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the point {id} is null", point.Iid); + } + else + { + point.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - point.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the point {id} is null", point.Iid); + } + else + { + point.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - point.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale x property of the point {id} is null", point.Iid); + } + else + { + point.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - point.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale y property of the point {id} is null", point.Iid); + } + else + { + point.Y = yProperty.GetSingle(); + } } return point; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index a98be4967..3f9da6d33 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,164 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteStateList.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + possibleFiniteStateList.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultState"u8, out var defaultStateProperty)) { - possibleFiniteStateList.DefaultState = jObject["defaultState"].ToObject(); + if(defaultStateProperty.ValueKind == JsonValueKind.Null) + { + possibleFiniteStateList.DefaultState = null; + } + else + { + possibleFiniteStateList.DefaultState = defaultStateProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteStateList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteStateList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteStateList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - possibleFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty)) { - possibleFiniteStateList.PossibleState.AddRange(jObject["possibleState"].ToOrderedItemCollection()); + possibleFiniteStateList.PossibleState.AddRange(possibleStateProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteStateList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index e0a389897..03d5087d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteState.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteState.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteState.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteState.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteState.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index 169c75fc7..e5864560b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PrefixedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PrefixedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - prefixedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + prefixedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + prefixedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + prefixedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + prefixedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + prefixedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - prefixedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - prefixedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["prefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("prefix"u8, out var prefixProperty)) { - prefixedUnit.Prefix = jObject["prefix"].ToObject(); + if(prefixProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale prefix property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.Prefix = prefixProperty.GetGuid(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - prefixedUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referenceUnit property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - prefixedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return prefixedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index e583d5355..8928ca912 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PublicationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Publication FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var publication = new CDP4Common.DTO.Publication(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PublicationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - publication.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var publication = new CDP4Common.DTO.Publication(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - publication.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - publication.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + publication.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + publication.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + publication.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - publication.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["publishedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedParameter"u8, out var publishedParameterProperty) && publishedParameterProperty.ValueKind != JsonValueKind.Null) { - publication.PublishedParameter.AddRange(jObject["publishedParameter"].ToObject>()); + foreach(var element in publishedParameterProperty.EnumerateArray()) + { + publication.PublishedParameter.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - publication.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the publication {id} is null", publication.Iid); + } + else + { + publication.ThingPreference = thingPreferenceProperty.GetString(); + } } return publication; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index 83a1d1442..ce4a93914 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class QuantityKindFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the QuantityKindFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - quantityKindFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - quantityKindFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale exponent property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - quantityKindFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["quantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKind"u8, out var quantityKindProperty)) { - quantityKindFactor.QuantityKind = jObject["quantityKind"].ToObject(); + if(quantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale quantityKind property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.QuantityKind = quantityKindProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - quantityKindFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } return quantityKindFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 4769b83b3..3f4d494dc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ratioScale = new CDP4Common.DTO.RatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ratioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ratioScale = new CDP4Common.DTO.RatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ratioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ratioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ratioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ratioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ratioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ratioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ratioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ratioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMaximumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ratioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isMinimumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ratioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ratioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ratioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maximumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ratioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minimumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ratioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ratioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ratioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale negativeValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ratioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale numberSet property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ratioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale positiveValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ratioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ratioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ratioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ratioScale.ValueDefinition.Add(element.GetGuid()); + } } return ratioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index 5288cfaed..4590d1a68 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,126 +28,231 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferenceSourceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferenceSource FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referenceSource = new CDP4Common.DTO.ReferenceSource(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferenceSourceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referenceSource.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referenceSource = new CDP4Common.DTO.ReferenceSource(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referenceSource.Alias.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - referenceSource.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Author = authorProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + referenceSource.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referenceSource.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referenceSource.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referenceSource.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referenceSource.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referenceSource.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referenceSource.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["language"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("language"u8, out var languageProperty)) { - referenceSource.Language = jObject["language"].ToObject(); + if(languageProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale language property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Language = languageProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referenceSource.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referenceSource.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Name = nameProperty.GetString(); + } } - if (!jObject["publicationYear"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publicationYear"u8, out var publicationYearProperty)) { - referenceSource.PublicationYear = jObject["publicationYear"].ToObject(); + if(publicationYearProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublicationYear = null; + } + else + { + referenceSource.PublicationYear = publicationYearProperty.GetInt32(); + } } - if (!jObject["publishedIn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedIn"u8, out var publishedInProperty)) { - referenceSource.PublishedIn = jObject["publishedIn"].ToObject(); + if(publishedInProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublishedIn = null; + } + else + { + referenceSource.PublishedIn = publishedInProperty.GetGuid(); + } } - if (!jObject["publisher"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publisher"u8, out var publisherProperty)) { - referenceSource.Publisher = jObject["publisher"].ToObject(); + if(publisherProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.Publisher = null; + } + else + { + referenceSource.Publisher = publisherProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referenceSource.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referenceSource.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["versionDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionDate"u8, out var versionDateProperty)) { - referenceSource.VersionDate = jObject["versionDate"].ToObject(); + if(versionDateProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.VersionDate = null; + } + else + { + referenceSource.VersionDate = versionDateProperty.GetDateTime(); + } } - if (!jObject["versionIdentifier"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionIdentifier"u8, out var versionIdentifierProperty)) { - referenceSource.VersionIdentifier = jObject["versionIdentifier"].ToObject(); + if(versionIdentifierProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale versionIdentifier property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.VersionIdentifier = versionIdentifierProperty.GetString(); + } } return referenceSource; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index 457e04d20..c965a9f79 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferencerRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferencerRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referencerRule = new CDP4Common.DTO.ReferencerRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferencerRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referencerRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referencerRule = new CDP4Common.DTO.ReferencerRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referencerRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referencerRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referencerRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referencerRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referencerRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referencerRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referencerRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxReferenced"u8, out var maxReferencedProperty)) { - referencerRule.MaxReferenced = jObject["maxReferenced"].ToObject(); + if(maxReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale maxReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MaxReferenced = maxReferencedProperty.GetInt32(); + } } - if (!jObject["minReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minReferenced"u8, out var minReferencedProperty)) { - referencerRule.MinReferenced = jObject["minReferenced"].ToObject(); + if(minReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale minReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MinReferenced = minReferencedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referencerRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referencerRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.Name = nameProperty.GetString(); + } } - if (!jObject["referencedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedCategory"u8, out var referencedCategoryProperty) && referencedCategoryProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ReferencedCategory.AddRange(jObject["referencedCategory"].ToObject>()); + foreach(var element in referencedCategoryProperty.EnumerateArray()) + { + referencerRule.ReferencedCategory.Add(element.GetGuid()); + } } - if (!jObject["referencingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencingCategory"u8, out var referencingCategoryProperty)) { - referencerRule.ReferencingCategory = jObject["referencingCategory"].ToObject(); + if(referencingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referencingCategory property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ReferencingCategory = referencingCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referencerRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referencerRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return referencerRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index 3dbc0bd33..77c392685 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationalExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationalExpression FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationalExpression.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationalExpressionResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationalExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationalExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationalExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationalExpression.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationalOperator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationalExpression.RelationalOperator = jObject["relationalOperator"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationalOperator"u8, out var relationalOperatorProperty)) { - relationalExpression.Scale = jObject["scale"].ToObject(); + if(relationalOperatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale relationalOperator property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.RelationalOperator = RelationalOperatorKindDeserializer.Deserialize(relationalOperatorProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationalExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationalExpression.Scale = null; + } + else + { + relationalExpression.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationalExpression.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + relationalExpression.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return relationalExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index 37c46402e..8437ea8ad 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationshipParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationshipParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationshipParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationshipParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationshipParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationshipParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationshipParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationshipParameterValue.Scale = null; + } + else + { + relationshipParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationshipParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + relationshipParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return relationshipParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index 634e54c22..f4bd88419 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForDeviationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForDeviationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForDeviation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForDeviation.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForDeviation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForDeviation.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForDeviation.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForDeviation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForDeviation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForDeviation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForDeviation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForDeviation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForDeviation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForDeviation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForDeviation.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForDeviation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForDeviation.PrimaryAnnotatedThing = null; + } + else + { + requestForDeviation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForDeviation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForDeviation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForDeviation.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForDeviation.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForDeviation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForDeviation.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Title = titleProperty.GetString(); + } } return requestForDeviation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index 81baab755..e957a5040 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForWaiverResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForWaiverResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForWaiver.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForWaiver.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForWaiver.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForWaiver.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForWaiver.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForWaiver.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForWaiver.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForWaiver.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForWaiver.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForWaiver.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForWaiver.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForWaiver.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForWaiver.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForWaiver.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForWaiver.PrimaryAnnotatedThing = null; + } + else + { + requestForWaiver.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForWaiver.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForWaiver.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForWaiver.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForWaiver.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForWaiver.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForWaiver.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Title = titleProperty.GetString(); + } } return requestForWaiver; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index 56507b5c4..5fde343c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,184 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Requirement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirement = new CDP4Common.DTO.Requirement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirement = new CDP4Common.DTO.Requirement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirement.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirement.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirement.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirement.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirement.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirement.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - requirement.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + requirement.Group = null; + } + else + { + requirement.Group = groupProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirement.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirement.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirement.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirement.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirement.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirement.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirement.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["parametricConstraint"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parametricConstraint"u8, out var parametricConstraintProperty)) { - requirement.ParametricConstraint.AddRange(jObject["parametricConstraint"].ToOrderedItemCollection()); + requirement.ParametricConstraint.AddRange(parametricConstraintProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirement.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index fc1aa8458..634d5fbf4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsContainerParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - requirementsContainerParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsContainerParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsContainerParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsContainerParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - requirementsContainerParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - requirementsContainerParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + requirementsContainerParameterValue.Scale = null; + } + else + { + requirementsContainerParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return requirementsContainerParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index acbf824eb..b6e4218e1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsGroup.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsGroup.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsGroup.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index 5a5b62c77..423026111 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsSpecificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsSpecificationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsSpecification.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsSpecification.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsSpecification.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsSpecification.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsSpecification.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsSpecification.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirementsSpecification.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsSpecification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsSpecification.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsSpecification.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsSpecification.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + requirementsSpecification.Requirement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsSpecification.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsSpecification.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsSpecification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index 27509f2b4..ad2873076 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,136 +28,247 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReviewItemDiscrepancyResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReviewItemDiscrepancyResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - reviewItemDiscrepancy.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - reviewItemDiscrepancy.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - reviewItemDiscrepancy.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale classification property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - reviewItemDiscrepancy.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - reviewItemDiscrepancy.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - reviewItemDiscrepancy.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - reviewItemDiscrepancy.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - reviewItemDiscrepancy.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - reviewItemDiscrepancy.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = null; + } + else + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + reviewItemDiscrepancy.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - reviewItemDiscrepancy.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["solution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("solution"u8, out var solutionProperty) && solutionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Solution.AddRange(jObject["solution"].ToObject>()); + foreach(var element in solutionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Solution.Add(element.GetGuid()); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + reviewItemDiscrepancy.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - reviewItemDiscrepancy.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - reviewItemDiscrepancy.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - reviewItemDiscrepancy.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale title property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Title = titleProperty.GetString(); + } } return reviewItemDiscrepancy; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index cf67bfc75..428b4121e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleVerificationListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleVerificationListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleVerificationList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ruleVerificationList.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ruleVerificationList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ruleVerificationList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleVerificationList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ruleVerificationList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - ruleVerificationList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["ruleVerification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerification"u8, out var ruleVerificationProperty)) { - ruleVerificationList.RuleVerification.AddRange(jObject["ruleVerification"].ToOrderedItemCollection()); + ruleVerificationList.RuleVerification.AddRange(ruleVerificationProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ruleVerificationList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleVerificationList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ThingPreference = thingPreferenceProperty.GetString(); + } } return ruleVerificationList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index d2a0bf8dc..45199c0de 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleViolationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleViolation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleViolation = new CDP4Common.DTO.RuleViolation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleViolationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleViolation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["description"].IsNullOrEmpty()) + var ruleViolation = new CDP4Common.DTO.RuleViolation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - ruleViolation.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale description property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleViolation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleViolation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleViolation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleViolation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["violatingThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("violatingThing"u8, out var violatingThingProperty) && violatingThingProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ViolatingThing.AddRange(jObject["violatingThing"].ToObject>()); + foreach(var element in violatingThingProperty.EnumerateArray()) + { + ruleViolation.ViolatingThing.Add(element.GetGuid()); + } } return ruleViolation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index a20356d1c..c1d7c617e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,116 +28,185 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SampledFunctionParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - sampledFunctionParameterType.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SampledFunctionParameterTypeResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sampledFunctionParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + sampledFunctionParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + sampledFunctionParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["degreeOfInterpolation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.DegreeOfInterpolation = jObject["degreeOfInterpolation"].ToObject(); + foreach(var element in definitionProperty.EnumerateArray()) + { + sampledFunctionParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dependentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("degreeOfInterpolation"u8, out var degreeOfInterpolationProperty)) { - sampledFunctionParameterType.DependentParameterType.AddRange(jObject["dependentParameterType"].ToOrderedItemCollection()); + if(degreeOfInterpolationProperty.ValueKind == JsonValueKind.Null) + { + sampledFunctionParameterType.DegreeOfInterpolation = null; + } + else + { + sampledFunctionParameterType.DegreeOfInterpolation = degreeOfInterpolationProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dependentParameterType"u8, out var dependentParameterTypeProperty)) { - sampledFunctionParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + sampledFunctionParameterType.DependentParameterType.AddRange(dependentParameterTypeProperty.ToOrderedItemCollection()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["independentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.IndependentParameterType.AddRange(jObject["independentParameterType"].ToOrderedItemCollection()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + sampledFunctionParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interpolationPeriod"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("independentParameterType"u8, out var independentParameterTypeProperty)) + { + sampledFunctionParameterType.IndependentParameterType.AddRange(independentParameterTypeProperty.ToOrderedItemCollection()); + } + if (jsonElement.TryGetProperty("interpolationPeriod"u8, out var interpolationPeriodProperty)) { - sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(jObject["interpolationPeriod"].ToString()); + sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(interpolationPeriodProperty.GetString()); } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - sampledFunctionParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sampledFunctionParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sampledFunctionParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - sampledFunctionParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - sampledFunctionParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sampledFunctionParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return sampledFunctionParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index 99820ab71..fde46eb30 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleReferenceQuantityValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleReferenceQuantityValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleReferenceQuantityValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleReferenceQuantityValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - scaleReferenceQuantityValue.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale scale property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleReferenceQuantityValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleReferenceQuantityValue.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale value property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Value = valueProperty.GetString(); + } } return scaleReferenceQuantityValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index 1c92f405c..3979cde6d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + scaleValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + scaleValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + scaleValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - scaleValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - scaleValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleValueDefinition.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale value property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Value = valueProperty.GetString(); + } } return scaleValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index 5a1501b5b..9dbef1bc9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SectionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Section FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var section = new CDP4Common.DTO.Section(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SectionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - section.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var section = new CDP4Common.DTO.Section(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - section.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + section.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - section.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the section {id} is null", section.Iid); + } + else + { + section.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + section.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + section.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - section.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the section {id} is null", section.Iid); + } + else + { + section.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - section.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the section {id} is null", section.Iid); + } + else + { + section.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - section.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the section {id} is null", section.Iid); + } + else + { + section.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["page"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("page"u8, out var pageProperty)) { - section.Page.AddRange(jObject["page"].ToOrderedItemCollection()); + section.Page.AddRange(pageProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - section.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the section {id} is null", section.Iid); + } + else + { + section.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - section.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the section {id} is null", section.Iid); + } + else + { + section.ThingPreference = thingPreferenceProperty.GetString(); + } } return section; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index e0a418fda..3508f96dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,126 +28,243 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SharedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SharedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sharedStyle = new CDP4Common.DTO.SharedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SharedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sharedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var sharedStyle = new CDP4Common.DTO.SharedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sharedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sharedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - sharedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillColor = null; + } + else + { + sharedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - sharedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillOpacity = null; + } + else + { + sharedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - sharedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontBold = null; + } + else + { + sharedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - sharedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontColor = null; + } + else + { + sharedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - sharedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontItalic = null; + } + else + { + sharedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - sharedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale fontName property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - sharedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontSize = null; + } + else + { + sharedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - sharedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontStrokeThrough = null; + } + else + { + sharedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - sharedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontUnderline = null; + } + else + { + sharedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sharedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sharedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - sharedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeColor = null; + } + else + { + sharedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - sharedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeOpacity = null; + } + else + { + sharedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - sharedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeWidth = null; + } + else + { + sharedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sharedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + sharedStyle.UsedColor.Add(element.GetGuid()); + } } return sharedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index 5ecd96249..bcc744308 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - simpleParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SimpleParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - simpleParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale parameterType property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - simpleParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + simpleParameterValue.Scale = null; + } + else + { + simpleParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - simpleParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + simpleParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return simpleParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index c3fe38746..b7b864b58 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,191 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + simpleQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - simpleQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale defaultScale property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + simpleQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - simpleQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale quantityDimensionSymbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - simpleQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index fe59a79b0..53ac8fc41 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index 1b05618ef..2d60b0f17 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataAnnotationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataAnnotationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataAnnotation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataAnnotation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataAnnotation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataAnnotation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataAnnotation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataAnnotation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - siteDirectoryDataAnnotation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale primaryAnnotatedThing property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataAnnotation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataAnnotation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 628d67c13..71d006535 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - siteDirectoryDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + siteDirectoryDataDiscussionItem.ReplyTo = null; + } + else + { + siteDirectoryDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index adb6a5d1f..57db9f6e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,141 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectory FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectory.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["annotation"].IsNullOrEmpty()) + var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("annotation"u8, out var annotationProperty) && annotationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Annotation.AddRange(jObject["annotation"].ToObject>()); + foreach(var element in annotationProperty.EnumerateArray()) + { + siteDirectory.Annotation.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectory.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["defaultParticipantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultParticipantRole"u8, out var defaultParticipantRoleProperty)) { - siteDirectory.DefaultParticipantRole = jObject["defaultParticipantRole"].ToObject(); + if(defaultParticipantRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultParticipantRole = null; + } + else + { + siteDirectory.DefaultParticipantRole = defaultParticipantRoleProperty.GetGuid(); + } } - if (!jObject["defaultPersonRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultPersonRole"u8, out var defaultPersonRoleProperty)) { - siteDirectory.DefaultPersonRole = jObject["defaultPersonRole"].ToObject(); + if(defaultPersonRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultPersonRole = null; + } + else + { + siteDirectory.DefaultPersonRole = defaultPersonRoleProperty.GetGuid(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + siteDirectory.Domain.Add(element.GetGuid()); + } } - if (!jObject["domainGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainGroup"u8, out var domainGroupProperty) && domainGroupProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.DomainGroup.AddRange(jObject["domainGroup"].ToObject>()); + foreach(var element in domainGroupProperty.EnumerateArray()) + { + siteDirectory.DomainGroup.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectory.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectory.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - siteDirectory.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale lastModifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + siteDirectory.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["model"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("model"u8, out var modelProperty) && modelProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Model.AddRange(jObject["model"].ToObject>()); + foreach(var element in modelProperty.EnumerateArray()) + { + siteDirectory.Model.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectory.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteDirectory.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.Name = nameProperty.GetString(); + } } - if (!jObject["naturalLanguage"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("naturalLanguage"u8, out var naturalLanguageProperty) && naturalLanguageProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.NaturalLanguage.AddRange(jObject["naturalLanguage"].ToObject>()); + foreach(var element in naturalLanguageProperty.EnumerateArray()) + { + siteDirectory.NaturalLanguage.Add(element.GetGuid()); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty) && organizationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Organization.AddRange(jObject["organization"].ToObject>()); + foreach(var element in organizationProperty.EnumerateArray()) + { + siteDirectory.Organization.Add(element.GetGuid()); + } } - if (!jObject["participantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantRole"u8, out var participantRoleProperty) && participantRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ParticipantRole.AddRange(jObject["participantRole"].ToObject>()); + foreach(var element in participantRoleProperty.EnumerateArray()) + { + siteDirectory.ParticipantRole.Add(element.GetGuid()); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty) && personProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Person.AddRange(jObject["person"].ToObject>()); + foreach(var element in personProperty.EnumerateArray()) + { + siteDirectory.Person.Add(element.GetGuid()); + } } - if (!jObject["personRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personRole"u8, out var personRoleProperty) && personRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.PersonRole.AddRange(jObject["personRole"].ToObject>()); + foreach(var element in personRoleProperty.EnumerateArray()) + { + siteDirectory.PersonRole.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteDirectory.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["siteReferenceDataLibrary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("siteReferenceDataLibrary"u8, out var siteReferenceDataLibraryProperty) && siteReferenceDataLibraryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.SiteReferenceDataLibrary.AddRange(jObject["siteReferenceDataLibrary"].ToObject>()); + foreach(var element in siteReferenceDataLibraryProperty.EnumerateArray()) + { + siteDirectory.SiteReferenceDataLibrary.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectory.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectory; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index ce8868802..28946bf18 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - siteDirectoryThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referencedRevisionNumber property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - siteDirectoryThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale referencedThing property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index 05fb25845..2e9c5fabe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,101 +28,171 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + siteLogEntry.Author = null; + } + else + { + siteLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + siteLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - siteLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale level property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + siteLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index 1a16f8e9f..fc7c9afdf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,151 +28,244 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - siteReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + siteReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + siteReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - siteReferenceDataLibrary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - siteReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + siteReferenceDataLibrary.RequiredRdl = null; + } + else + { + siteReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + siteReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return siteReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index f0f54c898..37940cf95 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SolutionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Solution FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var solution = new CDP4Common.DTO.Solution(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SolutionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - solution.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var solution = new CDP4Common.DTO.Solution(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - solution.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale author property of the solution {id} is null", solution.Iid); + } + else + { + solution.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - solution.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the solution {id} is null", solution.Iid); + } + else + { + solution.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - solution.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + solution.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + solution.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - solution.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the solution {id} is null", solution.Iid); + } + else + { + solution.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - solution.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - solution.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the solution {id} is null", solution.Iid); + } + else + { + solution.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - solution.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the solution {id} is null", solution.Iid); + } + else + { + solution.ThingPreference = thingPreferenceProperty.GetString(); + } } return solution; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index 128fae7d7..dc593f909 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,116 +28,203 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SpecializedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SpecializedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - specializedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + specializedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + specializedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - specializedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale defaultScale property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + specializedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["general"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("general"u8, out var generalProperty)) { - specializedQuantityKind.General = jObject["general"].ToObject(); + if(generalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale general property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.General = generalProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + specializedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - specializedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - specializedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - specializedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + specializedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - specializedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale quantityDimensionSymbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - specializedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - specializedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - specializedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return specializedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index ff54c2602..2a3d0bc4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,111 +28,175 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeHolderValueMap.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeHolderValueMap.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeHolderValueMap.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + stakeHolderValueMap.Goal.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeHolderValueMap.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeHolderValueMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.Name = nameProperty.GetString(); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + stakeHolderValueMap.Requirement.Add(element.GetGuid()); + } } - if (!jObject["settings"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("settings"u8, out var settingsProperty) && settingsProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Settings.AddRange(jObject["settings"].ToObject>()); + foreach(var element in settingsProperty.EnumerateArray()) + { + stakeHolderValueMap.Settings.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeHolderValueMap.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeHolderValueMap.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + stakeHolderValueMap.ValueGroup.Add(element.GetGuid()); + } } return stakeHolderValueMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index efb0af6bd..cf611c630 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapSettingsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapSettingsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMapSettings.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goalToValueGroupRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goalToValueGroupRelationship"u8, out var goalToValueGroupRelationshipProperty)) { - stakeHolderValueMapSettings.GoalToValueGroupRelationship = jObject["goalToValueGroupRelationship"].ToObject(); + if(goalToValueGroupRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = null; + } + else + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = goalToValueGroupRelationshipProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMapSettings.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["stakeholderValueToRequirementRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueToRequirementRelationship"u8, out var stakeholderValueToRequirementRelationshipProperty)) { - stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = jObject["stakeholderValueToRequirementRelationship"].ToObject(); + if(stakeholderValueToRequirementRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = null; + } + else + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = stakeholderValueToRequirementRelationshipProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMapSettings.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroupToStakeholderValueRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroupToStakeholderValueRelationship"u8, out var valueGroupToStakeholderValueRelationshipProperty)) { - stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = jObject["valueGroupToStakeholderValueRelationship"].ToObject(); + if(valueGroupToStakeholderValueRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = null; + } + else + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = valueGroupToStakeholderValueRelationshipProperty.GetGuid(); + } } return stakeHolderValueMapSettings; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index df57145da..36e471fef 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Stakeholder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholder = new CDP4Common.DTO.Stakeholder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholder = new CDP4Common.DTO.Stakeholder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholder.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholder.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholder.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholder.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholder.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholder.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeholder.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeholder.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index 36af14699..be7fa1876 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeholderValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholderValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholderValue.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholderValue.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholderValue.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholderValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholderValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholderValue.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholderValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholderValue.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholderValue.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholderValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholderValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 47dbc2b2d..775ad6bde 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TelephoneNumberResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TelephoneNumberResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - telephoneNumber.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + telephoneNumber.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + telephoneNumber.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - telephoneNumber.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - telephoneNumber.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - telephoneNumber.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty) && vcardTypeProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.VcardType.AddRange(jObject["vcardType"].ToObject>()); + foreach(var element in vcardTypeProperty.EnumerateArray()) + { + telephoneNumber.VcardType.Add(VcardTelephoneNumberKindDeserializer.Deserialize(element)); + } } return telephoneNumber; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index 0b1567f9a..a2a92daa0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TermResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Term FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var term = new CDP4Common.DTO.Term(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TermResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - term.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var term = new CDP4Common.DTO.Term(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - term.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + term.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - term.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + term.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + term.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + term.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - term.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + term.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - term.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the term {id} is null", term.Iid); + } + else + { + term.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - term.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the term {id} is null", term.Iid); + } + else + { + term.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - term.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the term {id} is null", term.Iid); + } + else + { + term.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - term.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the term {id} is null", term.Iid); + } + else + { + term.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - term.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the term {id} is null", term.Iid); + } + else + { + term.ThingPreference = thingPreferenceProperty.GetString(); + } } return term; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index 744222680..c88507401 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textParameterType = new CDP4Common.DTO.TextParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var textParameterType = new CDP4Common.DTO.TextParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + textParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + textParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - textParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + textParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - textParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - textParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return textParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index 4b6fbb167..490706e1d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextualNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextualNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textualNote = new CDP4Common.DTO.TextualNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextualNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textualNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var textualNote = new CDP4Common.DTO.TextualNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textualNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textualNote.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - textualNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale content property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - textualNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale createdOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textualNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textualNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - textualNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale languageCode property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textualNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textualNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - textualNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale owner property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textualNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textualNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return textualNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index dc2467aa2..218e355c7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TimeOfDayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TimeOfDayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - timeOfDayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + timeOfDayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + timeOfDayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + timeOfDayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + timeOfDayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - timeOfDayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - timeOfDayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - timeOfDayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - timeOfDayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - timeOfDayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale symbol property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - timeOfDayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return timeOfDayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index 9deaa29e9..147ac291c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitFactor = new CDP4Common.DTO.UnitFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var unitFactor = new CDP4Common.DTO.UnitFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - unitFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale exponent property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - unitFactor.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale unit property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Unit = unitProperty.GetGuid(); + } } return unitFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index f946c2757..9abd0988b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,91 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitPrefixResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitPrefix FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitPrefixResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitPrefix.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + unitPrefix.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - unitPrefix.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale conversionFactor property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + unitPrefix.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitPrefix.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitPrefix.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + unitPrefix.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - unitPrefix.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isDeprecated property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitPrefix.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - unitPrefix.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - unitPrefix.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitPrefix.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ThingPreference = thingPreferenceProperty.GetString(); + } } return unitPrefix; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index da543c27c..5a3ec842c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserPreferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserPreference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userPreference = new CDP4Common.DTO.UserPreference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UserPreferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userPreference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var userPreference = new CDP4Common.DTO.UserPreference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userPreference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userPreference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userPreference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - userPreference.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userPreference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - userPreference.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale value property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.Value = valueProperty.GetString(); + } } return userPreference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index 577879294..55801be0e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - userRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the UserRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - userRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + userRuleVerification.ExecutedOn = null; + } + else + { + userRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - userRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale isActive property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userRuleVerification.Rule = jObject["rule"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty)) { - userRuleVerification.Status = jObject["status"].ToObject(); + if(ruleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale rule property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Rule = ruleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - userRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale status property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return userRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index 6ae2c601c..8fe97a0b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -28,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ValueGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ValueGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var valueGroup = new CDP4Common.DTO.ValueGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ValueGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - valueGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var valueGroup = new CDP4Common.DTO.ValueGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + valueGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + valueGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + valueGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + valueGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + valueGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - valueGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + valueGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - valueGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale modifiedOn property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - valueGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale name property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - valueGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale shortName property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - valueGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Debug("The non-nullabale thingPreference property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return valueGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 52d716205..50c743b8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActionItem = CDP4Common.DTO.ActionItem; /// /// The purpose of the class is to provide a specific serializer @@ -44,103 +50,1079 @@ namespace CDP4JsonSerializer public class ActionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actionee", actionee => new JValue(actionee) }, - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "closeOutDate", closeOutDate => new JValue(closeOutDate != null ? ((DateTime)closeOutDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "closeOutStatement", closeOutStatement => new JValue(closeOutStatement) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "dueDate", dueDate => new JValue(((DateTime)dueDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActionItem actionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("actionee", this.PropertySerializerMap["actionee"](actionItem.Actionee)); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](actionItem.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](actionItem.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](actionItem.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), actionItem.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actionItem.ClassKind))); - jsonObject.Add("closeOutDate", this.PropertySerializerMap["closeOutDate"](actionItem.CloseOutDate)); - jsonObject.Add("closeOutStatement", this.PropertySerializerMap["closeOutStatement"](actionItem.CloseOutStatement)); - jsonObject.Add("content", this.PropertySerializerMap["content"](actionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](actionItem.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](actionItem.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dueDate", this.PropertySerializerMap["dueDate"](actionItem.DueDate)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](actionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actionItem.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actionItem.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](actionItem.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](actionItem.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actionItem.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](actionItem.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](actionItem.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), actionItem.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actionItem.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](actionItem.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actionee": + var allowedVersionsForActionee = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActionee.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actionee"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; + + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutdate": + var allowedVersionsForCloseOutDate = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCloseOutDate.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("closeOutDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutstatement": + var allowedVersionsForCloseOutStatement = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCloseOutStatement.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("closeOutStatement"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "duedate": + var allowedVersionsForDueDate = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDueDate.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("dueDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActionItem"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ActionItem actionItem) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); } - var actionItem = thing as ActionItem; - if (actionItem == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ActionItem."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.1.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.2.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.3.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WritePropertyName("actor"u8); + + if(actionItem.Actor.HasValue) + { + writer.WriteStringValue(actionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(actionItem); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index 7235e1abc..c7484c138 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteStateList = CDP4Common.DTO.ActualFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,566 @@ namespace CDP4JsonSerializer public class ActualFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JArray(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(((IEnumerable)possibleFiniteStateList).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteStateList actualFiniteStateList) - { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](actualFiniteStateList.ActualState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteStateList.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteStateList.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actualFiniteStateList.Owner)); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteStateList.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteStateList.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + var allowedVersionsForActualState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualState.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("actualState"u8); + + if(value is IEnumerable objectListActualState) + { + foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeoption": + var allowedVersionsForExcludeOption = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludeOption.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludeOption"u8); + + if(value is IEnumerable objectListExcludeOption) + { + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblefinitestatelist": + var allowedVersionsForPossibleFiniteStateList = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleFiniteStateList.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteStateList"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ActualFiniteStateList actualFiniteStateList) + { + throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); + return; } - var actualFiniteStateList = thing as ActualFiniteStateList; - if (actualFiniteStateList == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ActualFiniteStateList."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(actualFiniteStateList.Actor.HasValue) + { + writer.WriteStringValue(actualFiniteStateList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(actualFiniteStateList); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 69ada2f4a..0f93c24da 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,450 @@ namespace CDP4JsonSerializer public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "possibleState", possibleState => new JArray(possibleState) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteState actualFiniteState) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteState.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteState.Iid)); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ActualFiniteStateKind), actualFiniteState.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteState.ModifiedOn)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](actualFiniteState.PossibleState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteState.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteState.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "kind": + var allowedVersionsForKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((ActualFiniteStateKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + var allowedVersionsForPossibleState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleState.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleState"u8); + + if(value is IEnumerable objectListPossibleState) + { + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteState"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); + return; } - var actualFiniteState = thing as ActualFiniteState; - if (actualFiniteState == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ActualFiniteState."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(actualFiniteState.Actor.HasValue) + { + writer.WriteStringValue(actualFiniteState.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(actualFiniteState); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 62d8384d8..250910dbe 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Alias = CDP4Common.DTO.Alias; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class AliasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isSynonym", isSynonym => new JValue(isSynonym) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Alias alias) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), alias.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](alias.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](alias.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](alias.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](alias.Iid)); - jsonObject.Add("isSynonym", this.PropertySerializerMap["isSynonym"](alias.IsSynonym)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](alias.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](alias.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](alias.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](alias.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "issynonym": + var allowedVersionsForIsSynonym = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsSynonym.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isSynonym"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Alias"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); + return; } - var alias = thing as Alias; - if (alias == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Alias."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(alias.Actor.HasValue) + { + writer.WriteStringValue(alias.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(alias); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 9d3fdf76d..6b7bbe8aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using AndExpression = CDP4Common.DTO.AndExpression; /// /// The purpose of the class is to provide a specific serializer @@ -44,67 +50,416 @@ namespace CDP4JsonSerializer public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(AndExpression andExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), andExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](andExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](andExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](andExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](andExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](andExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](andExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](andExpression.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + var allowedVersionsForTerm = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTerm.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the AndExpression"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); + return; } - var andExpression = thing as AndExpression; - if (andExpression == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a AndExpression."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(andExpression.Actor.HasValue) + { + writer.WriteStringValue(andExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(andExpression); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 6520bdeb1..39477bf3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Approval = CDP4Common.DTO.Approval; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,532 @@ namespace CDP4JsonSerializer public class ApprovalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Approval approval) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](approval.Author)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationApprovalKind), approval.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), approval.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](approval.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](approval.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](approval.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](approval.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](approval.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](approval.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](approval.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](approval.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](approval.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](approval.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationApprovalKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Approval"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); + return; } - var approval = thing as Approval; - if (approval == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Approval."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(approval.Actor.HasValue) + { + writer.WriteStringValue(approval.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(approval); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 6d2c6992d..ee7e3e433 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ArrayParameterType = CDP4Common.DTO.ArrayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,89 +50,910 @@ namespace CDP4JsonSerializer public class ArrayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "dimension", dimension => new JArray(((IEnumerable)dimension).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "isTensor", isTensor => new JValue(isTensor) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ArrayParameterType arrayParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](arrayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](arrayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), arrayParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](arrayParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](arrayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dimension", this.PropertySerializerMap["dimension"](arrayParameterType.Dimension.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](arrayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](arrayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](arrayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](arrayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](arrayParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](arrayParameterType.IsFinalized)); - jsonObject.Add("isTensor", this.PropertySerializerMap["isTensor"](arrayParameterType.IsTensor)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](arrayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](arrayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](arrayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](arrayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](arrayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](arrayParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + var allowedVersionsForComponent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForComponent.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("component"u8); + + if(value is IEnumerable objectListComponent) + { + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "dimension": + var allowedVersionsForDimension = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDimension.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("dimension"u8); + + if(value is IEnumerable objectListDimension) + { + foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + var allowedVersionsForIsFinalized = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsFinalized.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "istensor": + var allowedVersionsForIsTensor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsTensor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isTensor"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ArrayParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ArrayParameterType arrayParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); } - var arrayParameterType = thing as ArrayParameterType; - if (arrayParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ArrayParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(arrayParameterType.Actor.HasValue) + { + writer.WriteStringValue(arrayParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(arrayParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 82178452c..d908fa88d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryNote = CDP4Common.DTO.BinaryNote; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,581 @@ namespace CDP4JsonSerializer public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "caption", caption => new JValue(caption) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JValue(fileType) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryNote binaryNote) - { - var jsonObject = new JObject(); - jsonObject.Add("caption", this.PropertySerializerMap["caption"](binaryNote.Caption)); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryNote.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](binaryNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](binaryNote.FileType)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryNote.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryNote.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "caption": + var allowedVersionsForCaption = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCaption.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("caption"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + var allowedVersionsForFileType = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFileType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fileType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryNote"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not BinaryNote binaryNote) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); } - var binaryNote = thing as BinaryNote; - if (binaryNote == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a BinaryNote."); + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.1.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.2.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryNote.Actor.HasValue) + { + writer.WriteStringValue(binaryNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(binaryNote); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 48b34af1c..68c5bc3ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationshipRule = CDP4Common.DTO.BinaryRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,804 @@ namespace CDP4JsonSerializer public class BinaryRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "forwardRelationshipName", forwardRelationshipName => new JValue(forwardRelationshipName) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "inverseRelationshipName", inverseRelationshipName => new JValue(inverseRelationshipName) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceCategory", sourceCategory => new JValue(sourceCategory) }, - { "targetCategory", targetCategory => new JValue(targetCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationshipRule binaryRelationshipRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](binaryRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](binaryRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("forwardRelationshipName", this.PropertySerializerMap["forwardRelationshipName"](binaryRelationshipRule.ForwardRelationshipName)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](binaryRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationshipRule.Iid)); - jsonObject.Add("inverseRelationshipName", this.PropertySerializerMap["inverseRelationshipName"](binaryRelationshipRule.InverseRelationshipName)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](binaryRelationshipRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationshipRule.Name)); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](binaryRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryRelationshipRule.ShortName)); - jsonObject.Add("sourceCategory", this.PropertySerializerMap["sourceCategory"](binaryRelationshipRule.SourceCategory)); - jsonObject.Add("targetCategory", this.PropertySerializerMap["targetCategory"](binaryRelationshipRule.TargetCategory)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationshipRule.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "forwardrelationshipname": + var allowedVersionsForForwardRelationshipName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForForwardRelationshipName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("forwardRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "inverserelationshipname": + var allowedVersionsForInverseRelationshipName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForInverseRelationshipName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("inverseRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationshipcategory": + var allowedVersionsForRelationshipCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelationshipCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourcecategory": + var allowedVersionsForSourceCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "targetcategory": + var allowedVersionsForTargetCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTargetCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("targetCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationshipRule"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not BinaryRelationshipRule binaryRelationshipRule) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); } - var binaryRelationshipRule = thing as BinaryRelationshipRule; - if (binaryRelationshipRule == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a BinaryRelationshipRule."); + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationshipRule.Actor.HasValue) + { + writer.WriteStringValue(binaryRelationshipRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(binaryRelationshipRule); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index 8537e6a20..f7c686f76 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationship = CDP4Common.DTO.BinaryRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,595 @@ namespace CDP4JsonSerializer public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationship binaryRelationship) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](binaryRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationship.RevisionNumber)); - jsonObject.Add("source", this.PropertySerializerMap["source"](binaryRelationship.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](binaryRelationship.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationship.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + var allowedVersionsForParameterValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + var allowedVersionsForSource = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSource.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + var allowedVersionsForTarget = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTarget.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationship"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not BinaryRelationship binaryRelationship) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); } - var binaryRelationship = thing as BinaryRelationship; - if (binaryRelationship == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a BinaryRelationship."); + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationship.Actor.HasValue) + { + writer.WriteStringValue(binaryRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(binaryRelationship); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index 80886dca3..55e95e544 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Book = CDP4Common.DTO.Book; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,568 @@ namespace CDP4JsonSerializer public class BookSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "section", section => new JArray(((IEnumerable)section).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Book book) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](book.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), book.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](book.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](book.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](book.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](book.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](book.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](book.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](book.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](book.RevisionNumber)); - jsonObject.Add("section", this.PropertySerializerMap["section"](book.Section.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](book.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](book.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "section": + var allowedVersionsForSection = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSection.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("section"u8); + + if(value is IEnumerable objectListSection) + { + foreach(var sectionItem in objectListSection.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Book"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Book book) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Book", nameof(thing)); } - var book = thing as Book; - if (book == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a Book."); + Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(book.Actor.HasValue) + { + writer.WriteStringValue(book.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(book); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index b712a5726..8bd6e5c00 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BooleanParameterType = CDP4Common.DTO.BooleanParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class BooleanParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BooleanParameterType booleanParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](booleanParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](booleanParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), booleanParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](booleanParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](booleanParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](booleanParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](booleanParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](booleanParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](booleanParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](booleanParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](booleanParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](booleanParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](booleanParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](booleanParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](booleanParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BooleanParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not BooleanParameterType booleanParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); } - var booleanParameterType = thing as BooleanParameterType; - if (booleanParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a BooleanParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(booleanParameterType.Actor.HasValue) + { + writer.WriteStringValue(booleanParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(booleanParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index 119b72d7d..f7d66e3c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Bounds = CDP4Common.DTO.Bounds; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,501 @@ namespace CDP4JsonSerializer public class BoundsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "height", height => new JValue(height) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "width", width => new JValue(width) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Bounds bounds) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), bounds.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](bounds.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](bounds.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("height", this.PropertySerializerMap["height"](bounds.Height)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](bounds.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](bounds.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](bounds.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](bounds.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](bounds.ThingPreference)); - jsonObject.Add("width", this.PropertySerializerMap["width"](bounds.Width)); - jsonObject.Add("x", this.PropertySerializerMap["x"](bounds.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](bounds.Y)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "height": + var allowedVersionsForHeight = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHeight.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("height"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "width": + var allowedVersionsForWidth = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForWidth.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("width"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + var allowedVersionsForX = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForX.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + var allowedVersionsForY = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForY.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Bounds"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Bounds bounds) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); } - var bounds = thing as Bounds; - if (bounds == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a Bounds."); + Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(bounds.Actor.HasValue) + { + writer.WriteStringValue(bounds.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(bounds); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 4ba1f9927..bbcf92878 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BuiltInRuleVerification = CDP4Common.DTO.BuiltInRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -44,74 +50,588 @@ namespace CDP4JsonSerializer public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BuiltInRuleVerification builtInRuleVerification) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), builtInRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](builtInRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](builtInRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](builtInRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](builtInRuleVerification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](builtInRuleVerification.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](builtInRuleVerification.RevisionNumber)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), builtInRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](builtInRuleVerification.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "executedon": + var allowedVersionsForExecutedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExecutedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + var allowedVersionsForIsActive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsActive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violation": + var allowedVersionsForViolation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForViolation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violation"u8); + + if(value is IEnumerable objectListViolation) + { + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BuiltInRuleVerification"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not BuiltInRuleVerification builtInRuleVerification) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); } - var builtInRuleVerification = thing as BuiltInRuleVerification; - if (builtInRuleVerification == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a BuiltInRuleVerification."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(builtInRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(builtInRuleVerification); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index 18a344b24..65054c330 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Category = CDP4Common.DTO.Category; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,784 @@ namespace CDP4JsonSerializer public class CategorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isAbstract", isAbstract => new JValue(isAbstract) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "permissibleClass", permissibleClass => new JArray(permissibleClass) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "superCategory", superCategory => new JArray(superCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Category category) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](category.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), category.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](category.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](category.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](category.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](category.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](category.Iid)); - jsonObject.Add("isAbstract", this.PropertySerializerMap["isAbstract"](category.IsAbstract)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](category.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](category.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](category.Name)); - jsonObject.Add("permissibleClass", this.PropertySerializerMap["permissibleClass"](category.PermissibleClass.Select(e => Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), e)))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](category.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](category.ShortName)); - jsonObject.Add("superCategory", this.PropertySerializerMap["superCategory"](category.SuperCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](category.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isabstract": + var allowedVersionsForIsAbstract = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsAbstract.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isAbstract"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "permissibleclass": + var allowedVersionsForPermissibleClass = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPermissibleClass.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("permissibleClass"u8); + + if(value is IEnumerable objectListPermissibleClass) + { + foreach(var permissibleClassItem in objectListPermissibleClass) + { + writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "supercategory": + var allowedVersionsForSuperCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSuperCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("superCategory"u8); + + if(value is IEnumerable objectListSuperCategory) + { + foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Category"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); + return; } - var category = thing as Category; - if (category == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Category."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(category.Actor.HasValue) + { + writer.WriteStringValue(category.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(category); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index 8d3f40220..eaa2878c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeProposal = CDP4Common.DTO.ChangeProposal; /// /// The purpose of the class is to provide a specific serializer @@ -44,97 +50,959 @@ namespace CDP4JsonSerializer public class ChangeProposalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeRequest", changeRequest => new JValue(changeRequest) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ChangeProposal changeProposal) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeProposal.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeProposal.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeProposal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeRequest", this.PropertySerializerMap["changeRequest"](changeProposal.ChangeRequest)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeProposal.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeProposal.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeProposal.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeProposal.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeProposal.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeProposal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeProposal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeProposal.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeProposal.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeProposal.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeProposal.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeProposal.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeProposal.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeProposal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeProposal.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeProposal.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeProposal.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeProposal.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeProposal.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "changerequest": + var allowedVersionsForChangeRequest = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForChangeRequest.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeRequest"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeProposal"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ChangeProposal changeProposal) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); } - var changeProposal = thing as ChangeProposal; - if (changeProposal == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ChangeProposal."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeProposal.Actor.HasValue) + { + writer.WriteStringValue(changeProposal.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(changeProposal); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index 9f66f39ba..2a227e46e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeRequest = CDP4Common.DTO.ChangeRequest; /// /// The purpose of the class is to provide a specific serializer @@ -44,95 +50,928 @@ namespace CDP4JsonSerializer public class ChangeRequestSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ChangeRequest changeRequest) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeRequest.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeRequest.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeRequest.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeRequest.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeRequest.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeRequest.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeRequest.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeRequest.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeRequest.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeRequest.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeRequest.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeRequest.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeRequest.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeRequest.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeRequest.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeRequest.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeRequest.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeRequest.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeRequest.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeRequest.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeRequest.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeRequest.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeRequest"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); + return; } - var changeRequest = thing as ChangeRequest; - if (changeRequest == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ChangeRequest."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeRequest.Actor.HasValue) + { + writer.WriteStringValue(changeRequest.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(changeRequest); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index e4c65cfad..51f47dc83 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Citation = CDP4Common.DTO.Citation; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,528 @@ namespace CDP4JsonSerializer public class CitationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isAdaptation", isAdaptation => new JValue(isAdaptation) }, - { "location", location => new JValue(location) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "remark", remark => new JValue(remark) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "source", source => new JValue(source) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Citation citation) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), citation.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](citation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](citation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](citation.Iid)); - jsonObject.Add("isAdaptation", this.PropertySerializerMap["isAdaptation"](citation.IsAdaptation)); - jsonObject.Add("location", this.PropertySerializerMap["location"](citation.Location)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](citation.ModifiedOn)); - jsonObject.Add("remark", this.PropertySerializerMap["remark"](citation.Remark)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](citation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](citation.ShortName)); - jsonObject.Add("source", this.PropertySerializerMap["source"](citation.Source)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](citation.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isadaptation": + var allowedVersionsForIsAdaptation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsAdaptation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isAdaptation"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "location": + var allowedVersionsForLocation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLocation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("location"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "remark": + var allowedVersionsForRemark = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRemark.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("remark"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + var allowedVersionsForSource = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSource.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Citation"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Citation citation) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); } - var citation = thing as Citation; - if (citation == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a Citation."); + Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(citation.Actor.HasValue) + { + writer.WriteStringValue(citation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(citation); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index a9057cd4d..6d9c521f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Color = CDP4Common.DTO.Color; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,494 @@ namespace CDP4JsonSerializer public class ColorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "blue", blue => new JValue(blue) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "green", green => new JValue(green) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "red", red => new JValue(red) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Color color) - { - var jsonObject = new JObject(); - jsonObject.Add("blue", this.PropertySerializerMap["blue"](color.Blue)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), color.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](color.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](color.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("green", this.PropertySerializerMap["green"](color.Green)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](color.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](color.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](color.Name)); - jsonObject.Add("red", this.PropertySerializerMap["red"](color.Red)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](color.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](color.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "blue": + var allowedVersionsForBlue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBlue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("blue"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "green": + var allowedVersionsForGreen = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGreen.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("green"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "red": + var allowedVersionsForRed = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRed.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("red"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Color"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Color color) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Color", nameof(thing)); } - var color = thing as Color; - if (color == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a Color."); + Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.0.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.1.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.2.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(color.Actor.HasValue) + { + writer.WriteStringValue(color.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(color); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index e38b7bd00..a5f4403a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CommonFileStore = CDP4Common.DTO.CommonFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,576 @@ namespace CDP4JsonSerializer public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CommonFileStore commonFileStore) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), commonFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](commonFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](commonFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](commonFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](commonFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](commonFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](commonFileStore.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](commonFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](commonFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](commonFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](commonFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](commonFileStore.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "file": + var allowedVersionsForFile = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFile.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("file"u8); + + if(value is IEnumerable objectListFile) + { + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + } + + writer.WriteEndArray(); + break; + case "folder": + var allowedVersionsForFolder = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFolder.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("folder"u8); + + if(value is IEnumerable objectListFolder) + { + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CommonFileStore"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not CommonFileStore commonFileStore) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); } - var commonFileStore = thing as CommonFileStore; - if (commonFileStore == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a CommonFileStore."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(commonFileStore.Actor.HasValue) + { + writer.WriteStringValue(commonFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(commonFileStore); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index 16358243c..7ab792415 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CompoundParameterType = CDP4Common.DTO.CompoundParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,818 @@ namespace CDP4JsonSerializer public class CompoundParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CompoundParameterType compoundParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](compoundParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](compoundParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), compoundParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](compoundParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](compoundParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](compoundParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](compoundParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](compoundParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](compoundParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](compoundParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](compoundParameterType.IsFinalized)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](compoundParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](compoundParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](compoundParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](compoundParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](compoundParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](compoundParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + var allowedVersionsForComponent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForComponent.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("component"u8); + + if(value is IEnumerable objectListComponent) + { + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + var allowedVersionsForIsFinalized = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsFinalized.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CompoundParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); + return; } - var compoundParameterType = thing as CompoundParameterType; - if (compoundParameterType == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a CompoundParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(compoundParameterType.Actor.HasValue) + { + writer.WriteStringValue(compoundParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(compoundParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index ceb9b8beb..6e2f969cc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Constant = CDP4Common.DTO.Constant; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,816 @@ namespace CDP4JsonSerializer public class ConstantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Constant constant) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](constant.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](constant.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), constant.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](constant.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](constant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](constant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](constant.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](constant.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](constant.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](constant.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](constant.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](constant.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](constant.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](constant.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](constant.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](constant.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](constant.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Constant"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Constant constant) + { + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); + return; } - var constant = thing as Constant; - if (constant == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Constant."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(constant.Actor.HasValue) + { + writer.WriteStringValue(constant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(constant); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 958eeb39f..494f45e35 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ContractChangeNotice = CDP4Common.DTO.ContractChangeNotice; /// /// The purpose of the class is to provide a specific serializer @@ -44,97 +50,959 @@ namespace CDP4JsonSerializer public class ContractChangeNoticeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeProposal", changeProposal => new JValue(changeProposal) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ContractChangeNotice contractChangeNotice) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](contractChangeNotice.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](contractChangeNotice.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](contractChangeNotice.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeProposal", this.PropertySerializerMap["changeProposal"](contractChangeNotice.ChangeProposal)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), contractChangeNotice.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), contractChangeNotice.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](contractChangeNotice.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](contractChangeNotice.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](contractChangeNotice.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](contractChangeNotice.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](contractChangeNotice.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](contractChangeNotice.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](contractChangeNotice.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](contractChangeNotice.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](contractChangeNotice.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](contractChangeNotice.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](contractChangeNotice.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), contractChangeNotice.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](contractChangeNotice.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](contractChangeNotice.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "changeproposal": + var allowedVersionsForChangeProposal = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForChangeProposal.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeProposal"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ContractChangeNotice"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ContractChangeNotice contractChangeNotice) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); } - var contractChangeNotice = thing as ContractChangeNotice; - if (contractChangeNotice == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ContractChangeNotice."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(contractChangeNotice.Actor.HasValue) + { + writer.WriteStringValue(contractChangeNotice.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(contractChangeNotice); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index 5845ccd59..74aba1f5b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CyclicRatioScale = CDP4Common.DTO.CyclicRatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,99 +50,1056 @@ namespace CDP4JsonSerializer public class CyclicRatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "modulus", modulus => new JValue(modulus) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CyclicRatioScale cyclicRatioScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](cyclicRatioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), cyclicRatioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](cyclicRatioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](cyclicRatioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](cyclicRatioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](cyclicRatioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](cyclicRatioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](cyclicRatioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](cyclicRatioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](cyclicRatioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](cyclicRatioScale.ModifiedOn)); - jsonObject.Add("modulus", this.PropertySerializerMap["modulus"](cyclicRatioScale.Modulus)); - jsonObject.Add("name", this.PropertySerializerMap["name"](cyclicRatioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](cyclicRatioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), cyclicRatioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](cyclicRatioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](cyclicRatioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](cyclicRatioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](cyclicRatioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](cyclicRatioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + var allowedVersionsForIsMaximumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + var allowedVersionsForIsMinimumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + var allowedVersionsForMappingToReferenceScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + var allowedVersionsForMaximumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + var allowedVersionsForMinimumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modulus": + var allowedVersionsForModulus = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModulus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modulus"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + var allowedVersionsForNegativeValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + var allowedVersionsForNumberSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + var allowedVersionsForPositiveValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CyclicRatioScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not CyclicRatioScale cyclicRatioScale) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); } - var cyclicRatioScale = thing as CyclicRatioScale; - if (cyclicRatioScale == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a CyclicRatioScale."); + Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(cyclicRatioScale.Actor.HasValue) + { + writer.WriteStringValue(cyclicRatioScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(cyclicRatioScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 6059c3f82..9835c3d53 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateParameterType = CDP4Common.DTO.DateParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class DateParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DateParameterType dateParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DateParameterType dateParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); } - var dateParameterType = thing as DateParameterType; - if (dateParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DateParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dateParameterType.Actor.HasValue) + { + writer.WriteStringValue(dateParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(dateParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index 57d229dbb..403c97965 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateTimeParameterType = CDP4Common.DTO.DateTimeParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class DateTimeParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DateTimeParameterType dateTimeParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateTimeParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateTimeParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateTimeParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateTimeParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateTimeParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateTimeParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateTimeParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateTimeParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateTimeParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateTimeParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateTimeParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateTimeParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateTimeParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateTimeParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DateTimeParameterType dateTimeParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); } - var dateTimeParameterType = thing as DateTimeParameterType; - if (dateTimeParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DateTimeParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dateTimeParameterType.Actor.HasValue) + { + writer.WriteStringValue(dateTimeParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(dateTimeParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index 1feb01bf2..9f49314eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DecompositionRule = CDP4Common.DTO.DecompositionRule; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,830 @@ namespace CDP4JsonSerializer public class DecompositionRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedCategory", containedCategory => new JArray(containedCategory) }, - { "containingCategory", containingCategory => new JValue(containingCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxContained", maxContained => new JValue(maxContained) }, - { "minContained", minContained => new JValue(minContained) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DecompositionRule decompositionRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](decompositionRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), decompositionRule.ClassKind))); - jsonObject.Add("containedCategory", this.PropertySerializerMap["containedCategory"](decompositionRule.ContainedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("containingCategory", this.PropertySerializerMap["containingCategory"](decompositionRule.ContainingCategory)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](decompositionRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](decompositionRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](decompositionRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](decompositionRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](decompositionRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](decompositionRule.IsDeprecated)); - jsonObject.Add("maxContained", this.PropertySerializerMap["maxContained"](decompositionRule.MaxContained)); - jsonObject.Add("minContained", this.PropertySerializerMap["minContained"](decompositionRule.MinContained)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](decompositionRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](decompositionRule.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](decompositionRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](decompositionRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](decompositionRule.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedcategory": + var allowedVersionsForContainedCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainedCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("containedCategory"u8); + + if(value is IEnumerable objectListContainedCategory) + { + foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "containingcategory": + var allowedVersionsForContainingCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainingCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxcontained": + var allowedVersionsForMaxContained = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaxContained.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mincontained": + var allowedVersionsForMinContained = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinContained.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DecompositionRule"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); + return; } - var decompositionRule = thing as DecompositionRule; - if (decompositionRule == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DecompositionRule."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(decompositionRule.Actor.HasValue) + { + writer.WriteStringValue(decompositionRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(decompositionRule); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 5819cc33a..dd3899aae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Definition = CDP4Common.DTO.Definition; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,600 @@ namespace CDP4JsonSerializer public class DefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "citation", citation => new JArray(citation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "example", example => new JArray(((IEnumerable)example).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Definition definition) - { - var jsonObject = new JObject(); - jsonObject.Add("citation", this.PropertySerializerMap["citation"](definition.Citation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), definition.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](definition.Content)); - jsonObject.Add("example", this.PropertySerializerMap["example"](definition.Example.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](definition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](definition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](definition.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](definition.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](definition.ModifiedOn)); - jsonObject.Add("note", this.PropertySerializerMap["note"](definition.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](definition.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](definition.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "citation": + var allowedVersionsForCitation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCitation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("citation"u8); + + if(value is IEnumerable objectListCitation) + { + foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "example": + var allowedVersionsForExample = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExample.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("example"u8); + + if(value is IEnumerable objectListExample) + { + foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + var allowedVersionsForNote = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNote.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("note"u8); + + if(value is IEnumerable objectListNote) + { + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Definition"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Definition definition) + { + throw new ArgumentException("The thing shall be a Definition", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); + return; } - var definition = thing as Definition; - if (definition == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Definition."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.0.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.1.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.2.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(definition.Actor.HasValue) + { + writer.WriteStringValue(definition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(definition); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 5b0223c39..f3f69c568 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DependentParameterTypeAssignment = CDP4Common.DTO.DependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,390 @@ namespace CDP4JsonSerializer public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DependentParameterTypeAssignment dependentParameterTypeAssignment) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dependentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dependentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](dependentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dependentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](dependentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dependentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dependentParameterTypeAssignment.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + var allowedVersionsForMeasurementScale = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMeasurementScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DependentParameterTypeAssignment"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); } - var dependentParameterTypeAssignment = thing as DependentParameterTypeAssignment; - if (dependentParameterTypeAssignment == null) + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DependentParameterTypeAssignment."); + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dependentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(dependentParameterTypeAssignment); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index cfd56cde5..1df35a4f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedQuantityKind = CDP4Common.DTO.DerivedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -44,89 +50,910 @@ namespace CDP4JsonSerializer public class DerivedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "quantityKindFactor", quantityKindFactor => new JArray(((IEnumerable)quantityKindFactor).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DerivedQuantityKind derivedQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](derivedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](derivedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](derivedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](derivedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("quantityKindFactor", this.PropertySerializerMap["quantityKindFactor"](derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](derivedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedQuantityKind.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + var allowedVersionsForDefaultScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + var allowedVersionsForPossibleScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + var allowedVersionsForQuantityDimensionSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykindfactor": + var allowedVersionsForQuantityKindFactor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForQuantityKindFactor.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("quantityKindFactor"u8); + + if(value is IEnumerable objectListQuantityKindFactor) + { + foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedQuantityKind"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DerivedQuantityKind derivedQuantityKind) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); } - var derivedQuantityKind = thing as DerivedQuantityKind; - if (derivedQuantityKind == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DerivedQuantityKind."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(derivedQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(derivedQuantityKind); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index ad8dea7a0..ecea0fcae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedUnit = CDP4Common.DTO.DerivedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class DerivedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unitFactor", unitFactor => new JArray(((IEnumerable)unitFactor).Cast().Select(x => x.ToJsonObject())) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DerivedUnit derivedUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedUnit.ThingPreference)); - jsonObject.Add("unitFactor", this.PropertySerializerMap["unitFactor"](derivedUnit.UnitFactor.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unitfactor": + var allowedVersionsForUnitFactor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnitFactor.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitFactor"u8); + + if(value is IEnumerable objectListUnitFactor) + { + foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DerivedUnit derivedUnit) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); } - var derivedUnit = thing as DerivedUnit; - if (derivedUnit == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a DerivedUnit."); + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedUnit.Actor.HasValue) + { + writer.WriteStringValue(derivedUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(derivedUnit); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index d9639848c..769a56402 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramCanvas = CDP4Common.DTO.DiagramCanvas; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,506 @@ namespace CDP4JsonSerializer public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramCanvas diagramCanvas) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramCanvas.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramCanvas.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](diagramCanvas.CreatedOn)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramCanvas.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramCanvas.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramCanvas.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramCanvas.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramCanvas.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramCanvas.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramCanvas.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramCanvas.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + var allowedVersionsForBounds = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBounds.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + var allowedVersionsForDiagramElement = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramCanvas"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DiagramCanvas diagramCanvas) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); } - var diagramCanvas = thing as DiagramCanvas; - if (diagramCanvas == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a DiagramCanvas."); + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramCanvas.Actor.HasValue) + { + writer.WriteStringValue(diagramCanvas.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(diagramCanvas); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 555bc86a6..54d41184c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramEdge = CDP4Common.DTO.DiagramEdge; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,751 @@ namespace CDP4JsonSerializer public class DiagramEdgeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "point", point => new JArray(((IEnumerable)point).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramEdge diagramEdge) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramEdge.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramEdge.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramEdge.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramEdge.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramEdge.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramEdge.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramEdge.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramEdge.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramEdge.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramEdge.Name)); - jsonObject.Add("point", this.PropertySerializerMap["point"](diagramEdge.Point.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramEdge.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramEdge.SharedStyle)); - jsonObject.Add("source", this.PropertySerializerMap["source"](diagramEdge.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](diagramEdge.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramEdge.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + var allowedVersionsForBounds = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBounds.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + var allowedVersionsForDepictedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDepictedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + var allowedVersionsForDiagramElement = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "localstyle": + var allowedVersionsForLocalStyle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLocalStyle.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("localStyle"u8); + + if(value is IEnumerable objectListLocalStyle) + { + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "point": + var allowedVersionsForPoint = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPoint.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("point"u8); + + if(value is IEnumerable objectListPoint) + { + foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + var allowedVersionsForSharedStyle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSharedStyle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + var allowedVersionsForSource = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSource.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + var allowedVersionsForTarget = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTarget.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramEdge"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); + return; } - var diagramEdge = thing as DiagramEdge; - if (diagramEdge == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a DiagramEdge."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramEdge.Actor.HasValue) + { + writer.WriteStringValue(diagramEdge.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(diagramEdge); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index d32672726..246cec687 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramObject = CDP4Common.DTO.DiagramObject; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,702 @@ namespace CDP4JsonSerializer public class DiagramObjectSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "documentation", documentation => new JValue(documentation) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "resolution", resolution => new JValue(resolution) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramObject diagramObject) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramObject.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramObject.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramObject.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramObject.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("documentation", this.PropertySerializerMap["documentation"](diagramObject.Documentation)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramObject.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramObject.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramObject.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramObject.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramObject.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramObject.Name)); - jsonObject.Add("resolution", this.PropertySerializerMap["resolution"](diagramObject.Resolution)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramObject.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramObject.SharedStyle)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramObject.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + var allowedVersionsForBounds = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBounds.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + var allowedVersionsForDepictedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDepictedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + var allowedVersionsForDiagramElement = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "documentation": + var allowedVersionsForDocumentation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDocumentation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("documentation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "localstyle": + var allowedVersionsForLocalStyle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLocalStyle.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("localStyle"u8); + + if(value is IEnumerable objectListLocalStyle) + { + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "resolution": + var allowedVersionsForResolution = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForResolution.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("resolution"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + var allowedVersionsForSharedStyle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSharedStyle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramObject"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DiagramObject diagramObject) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); } - var diagramObject = thing as DiagramObject; - if (diagramObject == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a DiagramObject."); + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramObject.Actor.HasValue) + { + writer.WriteStringValue(diagramObject.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(diagramObject); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index ce77fca09..150af9e1c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainFileStore = CDP4Common.DTO.DomainFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,610 @@ namespace CDP4JsonSerializer public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "isHidden", isHidden => new JValue(isHidden) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainFileStore domainFileStore) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](domainFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](domainFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](domainFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainFileStore.Iid)); - jsonObject.Add("isHidden", this.PropertySerializerMap["isHidden"](domainFileStore.IsHidden)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](domainFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainFileStore.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "file": + var allowedVersionsForFile = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFile.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("file"u8); + + if(value is IEnumerable objectListFile) + { + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + } + + writer.WriteEndArray(); + break; + case "folder": + var allowedVersionsForFolder = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFolder.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("folder"u8); + + if(value is IEnumerable objectListFolder) + { + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ishidden": + var allowedVersionsForIsHidden = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsHidden.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isHidden"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainFileStore"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DomainFileStore domainFileStore) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); } - var domainFileStore = thing as DomainFileStore; - if (domainFileStore == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a DomainFileStore."); + Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainFileStore.Actor.HasValue) + { + writer.WriteStringValue(domainFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(domainFileStore); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index b2198193c..39729d22c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertiseGroup = CDP4Common.DTO.DomainOfExpertiseGroup; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertiseGroup domainOfExpertiseGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertiseGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertiseGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertiseGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](domainOfExpertiseGroup.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertiseGroup.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertiseGroup.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertiseGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertiseGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertiseGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertiseGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertiseGroup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "domain": + var allowedVersionsForDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertiseGroup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); } - var domainOfExpertiseGroup = thing as DomainOfExpertiseGroup; - if (domainOfExpertiseGroup == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a DomainOfExpertiseGroup."); + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainOfExpertiseGroup.Actor.HasValue) + { + writer.WriteStringValue(domainOfExpertiseGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(domainOfExpertiseGroup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index 5054e25b6..d5fe53e4e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertise = CDP4Common.DTO.DomainOfExpertise; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertise domainOfExpertise) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertise.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](domainOfExpertise.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertise.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertise.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertise.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertise.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertise.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertise.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertise.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertise.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertise.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertise.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertise"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not DomainOfExpertise domainOfExpertise) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); } - var domainOfExpertise = thing as DomainOfExpertise; - if (domainOfExpertise == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a DomainOfExpertise."); + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainOfExpertise.Actor.HasValue) + { + writer.WriteStringValue(domainOfExpertise.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(domainOfExpertise); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index f2f5fe5de..79cf4552d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementDefinition = CDP4Common.DTO.ElementDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -44,89 +50,964 @@ namespace CDP4JsonSerializer public class ElementDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedElement", containedElement => new JArray(containedElement) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JArray(parameter) }, - { "parameterGroup", parameterGroup => new JArray(parameterGroup) }, - { "referencedElement", referencedElement => new JArray(referencedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ElementDefinition elementDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementDefinition.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementDefinition.ClassKind))); - jsonObject.Add("containedElement", this.PropertySerializerMap["containedElement"](elementDefinition.ContainedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementDefinition.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementDefinition.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](elementDefinition.Parameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterGroup", this.PropertySerializerMap["parameterGroup"](elementDefinition.ParameterGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencedElement", this.PropertySerializerMap["referencedElement"](elementDefinition.ReferencedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementDefinition.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedelement": + var allowedVersionsForContainedElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainedElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("containedElement"u8); + + if(value is IEnumerable objectListContainedElement) + { + foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + var allowedVersionsForOrganizationalParticipant = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganizationalParticipant.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organizationalParticipant"u8); + + if(value is IEnumerable objectListOrganizationalParticipant) + { + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + } + + writer.WriteEndArray(); + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + var allowedVersionsForParameter = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameter.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameter"u8); + + if(value is IEnumerable objectListParameter) + { + foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + } + + writer.WriteEndArray(); + break; + case "parametergroup": + var allowedVersionsForParameterGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterGroup"u8); + + if(value is IEnumerable objectListParameterGroup) + { + foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + } + + writer.WriteEndArray(); + break; + case "referencedelement": + var allowedVersionsForReferencedElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referencedElement"u8); + + if(value is IEnumerable objectListReferencedElement) + { + foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementDefinition"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ElementDefinition elementDefinition) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); } - var elementDefinition = thing as ElementDefinition; - if (elementDefinition == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ElementDefinition."); + Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(elementDefinition.Actor.HasValue) + { + writer.WriteStringValue(elementDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(elementDefinition); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 6398d0a3f..1653d0d9a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementUsage = CDP4Common.DTO.ElementUsage; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,876 @@ namespace CDP4JsonSerializer public class ElementUsageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "elementDefinition", elementDefinition => new JValue(elementDefinition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "interfaceEnd", interfaceEnd => new JValue(interfaceEnd.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterOverride", parameterOverride => new JArray(parameterOverride) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ElementUsage elementUsage) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementUsage.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementUsage.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementUsage.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementUsage.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("elementDefinition", this.PropertySerializerMap["elementDefinition"](elementUsage.ElementDefinition)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementUsage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementUsage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](elementUsage.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementUsage.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementUsage.Iid)); - jsonObject.Add("interfaceEnd", this.PropertySerializerMap["interfaceEnd"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.InterfaceEndKind), elementUsage.InterfaceEnd))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementUsage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementUsage.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementUsage.Owner)); - jsonObject.Add("parameterOverride", this.PropertySerializerMap["parameterOverride"](elementUsage.ParameterOverride.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementUsage.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementUsage.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementUsage.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "elementdefinition": + var allowedVersionsForElementDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForElementDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("elementDefinition"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeoption": + var allowedVersionsForExcludeOption = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludeOption.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludeOption"u8); + + if(value is IEnumerable objectListExcludeOption) + { + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "interfaceend": + var allowedVersionsForInterfaceEnd = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForInterfaceEnd.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("interfaceEnd"u8); + + if(value != null) + { + writer.WriteStringValue(((InterfaceEndKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameteroverride": + var allowedVersionsForParameterOverride = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterOverride.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterOverride"u8); + + if(value is IEnumerable objectListParameterOverride) + { + foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementUsage"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ElementUsage elementUsage) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); } - var elementUsage = thing as ElementUsage; - if (elementUsage == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ElementUsage."); + Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(elementUsage.Actor.HasValue) + { + writer.WriteStringValue(elementUsage.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(elementUsage); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index c1336a7eb..806e68b7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EmailAddress = CDP4Common.DTO.EmailAddress; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JValue(vcardType.ToString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EmailAddress emailAddress) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), emailAddress.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](emailAddress.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](emailAddress.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](emailAddress.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](emailAddress.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](emailAddress.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](emailAddress.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](emailAddress.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardEmailAddressKind), emailAddress.VcardType))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + var allowedVersionsForVcardType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForVcardType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("vcardType"u8); + + if(value != null) + { + writer.WriteStringValue(((VcardEmailAddressKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EmailAddress"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EmailAddress emailAddress) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); } - var emailAddress = thing as EmailAddress; - if (emailAddress == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a EmailAddress."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(emailAddress.Actor.HasValue) + { + writer.WriteStringValue(emailAddress.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(emailAddress); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index 591cacaea..b2c6ba21d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataDiscussionItem = CDP4Common.DTO.EngineeringModelDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,528 @@ namespace CDP4JsonSerializer public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](engineeringModelDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataDiscussionItem.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + var allowedVersionsForReplyTo = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReplyTo.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataDiscussionItem"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); } - var engineeringModelDataDiscussionItem = thing as EngineeringModelDataDiscussionItem; - if (engineeringModelDataDiscussionItem == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataDiscussionItem."); + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(engineeringModelDataDiscussionItem); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 01ee7fb87..58c900552 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataNote = CDP4Common.DTO.EngineeringModelDataNote; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,626 @@ namespace CDP4JsonSerializer public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataNote engineeringModelDataNote) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataNote.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataNote.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](engineeringModelDataNote.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataNote.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](engineeringModelDataNote.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataNote.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataNote.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataNote"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EngineeringModelDataNote engineeringModelDataNote) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); } - var engineeringModelDataNote = thing as EngineeringModelDataNote; - if (engineeringModelDataNote == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataNote."); + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataNote.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(engineeringModelDataNote); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 00542d683..e1215330c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModel = CDP4Common.DTO.EngineeringModel; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,747 @@ namespace CDP4JsonSerializer public class EngineeringModelSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "book", book => new JArray(((IEnumerable)book).Cast().Select(x => x.ToJsonObject())) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "commonFileStore", commonFileStore => new JArray(commonFileStore) }, - { "engineeringModelSetup", engineeringModelSetup => new JValue(engineeringModelSetup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "genericNote", genericNote => new JArray(genericNote) }, - { "iid", iid => new JValue(iid) }, - { "iteration", iteration => new JArray(iteration) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "modellingAnnotation", modellingAnnotation => new JArray(modellingAnnotation) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModel engineeringModel) - { - var jsonObject = new JObject(); - jsonObject.Add("book", this.PropertySerializerMap["book"](engineeringModel.Book.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModel.ClassKind))); - jsonObject.Add("commonFileStore", this.PropertySerializerMap["commonFileStore"](engineeringModel.CommonFileStore)); - jsonObject.Add("engineeringModelSetup", this.PropertySerializerMap["engineeringModelSetup"](engineeringModel.EngineeringModelSetup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModel.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModel.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("genericNote", this.PropertySerializerMap["genericNote"](engineeringModel.GenericNote.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModel.Iid)); - jsonObject.Add("iteration", this.PropertySerializerMap["iteration"](engineeringModel.Iteration.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](engineeringModel.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](engineeringModel.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modellingAnnotation", this.PropertySerializerMap["modellingAnnotation"](engineeringModel.ModellingAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModel.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModel.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModel.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "book": + var allowedVersionsForBook = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBook.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("book"u8); + + if(value is IEnumerable objectListBook) + { + foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "commonfilestore": + var allowedVersionsForCommonFileStore = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCommonFileStore.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("commonFileStore"u8); + + if(value is IEnumerable objectListCommonFileStore) + { + foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + } + + writer.WriteEndArray(); + break; + case "engineeringmodelsetup": + var allowedVersionsForEngineeringModelSetup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForEngineeringModelSetup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("engineeringModelSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "genericnote": + var allowedVersionsForGenericNote = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGenericNote.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("genericNote"u8); + + if(value is IEnumerable objectListGenericNote) + { + foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iteration": + var allowedVersionsForIteration = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIteration.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("iteration"u8); + + if(value is IEnumerable objectListIteration) + { + foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + } + + writer.WriteEndArray(); + break; + case "lastmodifiedon": + var allowedVersionsForLastModifiedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLastModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + var allowedVersionsForLogEntry = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLogEntry.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntry"u8); + + if(value is IEnumerable objectListLogEntry) + { + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + } + + writer.WriteEndArray(); + break; + case "modellingannotation": + var allowedVersionsForModellingAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModellingAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("modellingAnnotation"u8); + + if(value is IEnumerable objectListModellingAnnotation) + { + foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModel"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EngineeringModel engineeringModel) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); } - var engineeringModel = thing as EngineeringModel; - if (engineeringModel == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a EngineeringModel."); + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.1.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.2.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModel.Actor.HasValue) + { + writer.WriteStringValue(engineeringModel.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(engineeringModel); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index de8252109..a26486065 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelSetup = CDP4Common.DTO.EngineeringModelSetup; /// /// The purpose of the class is to provide a specific serializer @@ -44,95 +50,1090 @@ namespace CDP4JsonSerializer public class EngineeringModelSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "activeDomain", activeDomain => new JArray(activeDomain) }, - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOrganizationalParticipant", defaultOrganizationalParticipant => new JValue(defaultOrganizationalParticipant) }, - { "definition", definition => new JArray(definition) }, - { "engineeringModelIid", engineeringModelIid => new JValue(engineeringModelIid) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JArray(iterationSetup) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "participant", participant => new JArray(participant) }, - { "requiredRdl", requiredRdl => new JArray(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceEngineeringModelSetupIid", sourceEngineeringModelSetupIid => new JValue(sourceEngineeringModelSetupIid) }, - { "studyPhase", studyPhase => new JValue(studyPhase.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelSetup engineeringModelSetup) - { - var jsonObject = new JObject(); - jsonObject.Add("activeDomain", this.PropertySerializerMap["activeDomain"](engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](engineeringModelSetup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelSetup.ClassKind))); - jsonObject.Add("defaultOrganizationalParticipant", this.PropertySerializerMap["defaultOrganizationalParticipant"](engineeringModelSetup.DefaultOrganizationalParticipant)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](engineeringModelSetup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("engineeringModelIid", this.PropertySerializerMap["engineeringModelIid"](engineeringModelSetup.EngineeringModelIid)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](engineeringModelSetup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelSetup.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](engineeringModelSetup.IterationSetup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.EngineeringModelKind), engineeringModelSetup.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelSetup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](engineeringModelSetup.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participant", this.PropertySerializerMap["participant"](engineeringModelSetup.Participant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](engineeringModelSetup.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelSetup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](engineeringModelSetup.ShortName)); - jsonObject.Add("sourceEngineeringModelSetupIid", this.PropertySerializerMap["sourceEngineeringModelSetupIid"](engineeringModelSetup.SourceEngineeringModelSetupIid)); - jsonObject.Add("studyPhase", this.PropertySerializerMap["studyPhase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.StudyPhaseKind), engineeringModelSetup.StudyPhase))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelSetup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "activedomain": + var allowedVersionsForActiveDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActiveDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("activeDomain"u8); + + if(value is IEnumerable objectListActiveDomain) + { + foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; + + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultorganizationalparticipant": + var allowedVersionsForDefaultOrganizationalParticipant = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultOrganizationalParticipant.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "engineeringmodeliid": + var allowedVersionsForEngineeringModelIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForEngineeringModelIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("engineeringModelIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + var allowedVersionsForIterationSetup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIterationSetup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("iterationSetup"u8); + + if(value is IEnumerable objectListIterationSetup) + { + foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + } + + writer.WriteEndArray(); + break; + case "kind": + var allowedVersionsForKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((EngineeringModelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + var allowedVersionsForOrganizationalParticipant = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganizationalParticipant.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organizationalParticipant"u8); + + if(value is IEnumerable objectListOrganizationalParticipant) + { + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + } + + writer.WriteEndArray(); + break; + case "participant": + var allowedVersionsForParticipant = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParticipant.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participant"u8); + + if(value is IEnumerable objectListParticipant) + { + foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + var allowedVersionsForRequiredRdl = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requiredRdl"u8); + + if(value is IEnumerable objectListRequiredRdl) + { + foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceengineeringmodelsetupiid": + var allowedVersionsForSourceEngineeringModelSetupIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceEngineeringModelSetupIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "studyphase": + var allowedVersionsForStudyPhase = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStudyPhase.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("studyPhase"u8); + + if(value != null) + { + writer.WriteStringValue(((StudyPhaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelSetup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); + return; } - var engineeringModelSetup = thing as EngineeringModelSetup; - if (engineeringModelSetup == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a EngineeringModelSetup."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.0.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.1.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.2.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.3.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("actor"u8); + + if(engineeringModelSetup.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(engineeringModelSetup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 5a28df53c..17bfcb6e1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationParameterType = CDP4Common.DTO.EnumerationParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,818 @@ namespace CDP4JsonSerializer public class EnumerationParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "allowMultiSelect", allowMultiSelect => new JValue(allowMultiSelect) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueDefinition", valueDefinition => new JArray(((IEnumerable)valueDefinition).Cast().Select(x => x.ToJsonObject())) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EnumerationParameterType enumerationParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("allowMultiSelect", this.PropertySerializerMap["allowMultiSelect"](enumerationParameterType.AllowMultiSelect)); - jsonObject.Add("category", this.PropertySerializerMap["category"](enumerationParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](enumerationParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](enumerationParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationParameterType.ThingPreference)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](enumerationParameterType.ValueDefinition.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "allowmultiselect": + var allowedVersionsForAllowMultiSelect = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAllowMultiSelect.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("allowMultiSelect"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); + return; } - var enumerationParameterType = thing as EnumerationParameterType; - if (enumerationParameterType == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a EnumerationParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(enumerationParameterType.Actor.HasValue) + { + writer.WriteStringValue(enumerationParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(enumerationParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 6db280244..03c22ebbd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationValueDefinition = CDP4Common.DTO.EnumerationValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,600 @@ namespace CDP4JsonSerializer public class EnumerationValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EnumerationValueDefinition enumerationValueDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationValueDefinition.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationValueDefinition"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not EnumerationValueDefinition enumerationValueDefinition) + { + throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); + return; } - var enumerationValueDefinition = thing as EnumerationValueDefinition; - if (enumerationValueDefinition == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a EnumerationValueDefinition."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(enumerationValueDefinition.Actor.HasValue) + { + writer.WriteStringValue(enumerationValueDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(enumerationValueDefinition); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index f862c9c34..53ec45716 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExclusiveOrExpression = CDP4Common.DTO.ExclusiveOrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -44,67 +50,416 @@ namespace CDP4JsonSerializer public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ExclusiveOrExpression exclusiveOrExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), exclusiveOrExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](exclusiveOrExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](exclusiveOrExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](exclusiveOrExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](exclusiveOrExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](exclusiveOrExpression.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + var allowedVersionsForTerm = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTerm.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExclusiveOrExpression"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); + return; } - var exclusiveOrExpression = thing as ExclusiveOrExpression; - if (exclusiveOrExpression == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ExclusiveOrExpression."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(exclusiveOrExpression.Actor.HasValue) + { + writer.WriteStringValue(exclusiveOrExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(exclusiveOrExpression); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index a69eed343..90f4cc197 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExternalIdentifierMap = CDP4Common.DTO.ExternalIdentifierMap; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,656 @@ namespace CDP4JsonSerializer public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "correspondence", correspondence => new JArray(correspondence) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalFormat", externalFormat => new JValue(externalFormat) }, - { "externalModelName", externalModelName => new JValue(externalModelName) }, - { "externalToolName", externalToolName => new JValue(externalToolName) }, - { "externalToolVersion", externalToolVersion => new JValue(externalToolVersion) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ExternalIdentifierMap externalIdentifierMap) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), externalIdentifierMap.ClassKind))); - jsonObject.Add("correspondence", this.PropertySerializerMap["correspondence"](externalIdentifierMap.Correspondence.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalFormat", this.PropertySerializerMap["externalFormat"](externalIdentifierMap.ExternalFormat)); - jsonObject.Add("externalModelName", this.PropertySerializerMap["externalModelName"](externalIdentifierMap.ExternalModelName)); - jsonObject.Add("externalToolName", this.PropertySerializerMap["externalToolName"](externalIdentifierMap.ExternalToolName)); - jsonObject.Add("externalToolVersion", this.PropertySerializerMap["externalToolVersion"](externalIdentifierMap.ExternalToolVersion)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](externalIdentifierMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](externalIdentifierMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](externalIdentifierMap.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](externalIdentifierMap.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](externalIdentifierMap.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](externalIdentifierMap.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "correspondence": + var allowedVersionsForCorrespondence = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCorrespondence.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("correspondence"u8); + + if(value is IEnumerable objectListCorrespondence) + { + foreach(var correspondenceItem in objectListCorrespondence.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalformat": + var allowedVersionsForExternalFormat = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalFormat.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalFormat"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externalmodelname": + var allowedVersionsForExternalModelName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalModelName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalModelName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolname": + var allowedVersionsForExternalToolName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalToolName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalToolName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolversion": + var allowedVersionsForExternalToolVersion = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalToolVersion.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalToolVersion"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExternalIdentifierMap"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); + return; } - var externalIdentifierMap = thing as ExternalIdentifierMap; - if (externalIdentifierMap == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ExternalIdentifierMap."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(externalIdentifierMap.Actor.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(externalIdentifierMap); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 088c56547..3fe0cb979 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileRevision = CDP4Common.DTO.FileRevision; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,622 @@ namespace CDP4JsonSerializer public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "contentHash", contentHash => new JValue(contentHash) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(((IEnumerable)fileType).Cast().Select(x => x.ToJsonObject())) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(FileRevision fileRevision) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileRevision.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](fileRevision.ContainingFolder)); - jsonObject.Add("contentHash", this.PropertySerializerMap["contentHash"](fileRevision.ContentHash)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](fileRevision.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](fileRevision.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileRevision.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileRevision.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](fileRevision.FileType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileRevision.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileRevision.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileRevision.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileRevision.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileRevision.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containingfolder": + var allowedVersionsForContainingFolder = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainingFolder.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "contenthash": + var allowedVersionsForContentHash = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContentHash.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("contentHash"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + var allowedVersionsForCreator = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreator.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + var allowedVersionsForFileType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFileType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileRevision"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not FileRevision fileRevision) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); } - var fileRevision = thing as FileRevision; - if (fileRevision == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a FileRevision."); + Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileRevision.Actor.HasValue) + { + writer.WriteStringValue(fileRevision.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(fileRevision); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 77d02b75e..402554d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using File = CDP4Common.DTO.File; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,578 @@ namespace CDP4JsonSerializer public class FileSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileRevision", fileRevision => new JArray(fileRevision) }, - { "iid", iid => new JValue(iid) }, - { "lockedBy", lockedBy => new JValue(lockedBy) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(File file) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](file.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), file.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](file.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](file.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileRevision", this.PropertySerializerMap["fileRevision"](file.FileRevision.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](file.Iid)); - jsonObject.Add("lockedBy", this.PropertySerializerMap["lockedBy"](file.LockedBy)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](file.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](file.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](file.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](file.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filerevision": + var allowedVersionsForFileRevision = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFileRevision.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileRevision"u8); + + if(value is IEnumerable objectListFileRevision) + { + foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lockedby": + var allowedVersionsForLockedBy = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLockedBy.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lockedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the File"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not File file) + { + throw new ArgumentException("The thing shall be a File", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); + return; } - var file = thing as File; - if (file == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a File."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing File for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing File for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing File for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing File for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(file.Actor.HasValue) + { + writer.WriteStringValue(file.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(file); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 70b0d6254..71b13359f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileType = CDP4Common.DTO.FileType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class FileTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "extension", extension => new JValue(extension) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(FileType fileType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](fileType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](fileType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](fileType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("extension", this.PropertySerializerMap["extension"](fileType.Extension)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](fileType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](fileType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](fileType.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "extension": + var allowedVersionsForExtension = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExtension.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("extension"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not FileType fileType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); } - var fileType = thing as FileType; - if (fileType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a FileType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileType.Actor.HasValue) + { + writer.WriteStringValue(fileType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(fileType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 7498f4963..fa69502d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Folder = CDP4Common.DTO.Folder; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,564 @@ namespace CDP4JsonSerializer public class FolderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Folder folder) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), folder.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](folder.ContainingFolder)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](folder.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](folder.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](folder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](folder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](folder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](folder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](folder.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](folder.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](folder.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](folder.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containingfolder": + var allowedVersionsForContainingFolder = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainingFolder.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + var allowedVersionsForCreator = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreator.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Folder"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Folder folder) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); } - var folder = thing as Folder; - if (folder == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Folder."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(folder.Actor.HasValue) + { + writer.WriteStringValue(folder.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(folder); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index c3bd06769..b6bdf9a64 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Glossary = CDP4Common.DTO.Glossary; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,750 @@ namespace CDP4JsonSerializer public class GlossarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Glossary glossary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](glossary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](glossary.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), glossary.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](glossary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](glossary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](glossary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](glossary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](glossary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](glossary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](glossary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](glossary.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](glossary.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](glossary.ShortName)); - jsonObject.Add("term", this.PropertySerializerMap["term"](glossary.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](glossary.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + var allowedVersionsForTerm = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTerm.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Glossary"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Glossary glossary) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); } - var glossary = thing as Glossary; - if (glossary == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a Glossary."); + Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(glossary.Actor.HasValue) + { + writer.WriteStringValue(glossary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(glossary); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index bf95adc37..6d418939f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Goal = CDP4Common.DTO.Goal; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,604 @@ namespace CDP4JsonSerializer public class GoalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Goal goal) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](goal.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](goal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), goal.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](goal.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](goal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](goal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](goal.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](goal.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](goal.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](goal.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](goal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](goal.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](goal.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Goal"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); + return; } - var goal = thing as Goal; - if (goal == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Goal."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(goal.Actor.HasValue) + { + writer.WriteStringValue(goal.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(goal); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 8d65c3abc..13174fe29 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using HyperLink = CDP4Common.DTO.HyperLink; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "uri", uri => new JValue(uri) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(HyperLink hyperLink) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), hyperLink.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](hyperLink.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](hyperLink.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](hyperLink.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](hyperLink.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](hyperLink.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](hyperLink.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](hyperLink.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](hyperLink.ThingPreference)); - jsonObject.Add("uri", this.PropertySerializerMap["uri"](hyperLink.Uri)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "uri": + var allowedVersionsForUri = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUri.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("uri"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the HyperLink"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); + return; } - var hyperLink = thing as HyperLink; - if (hyperLink == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a HyperLink."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(hyperLink.Actor.HasValue) + { + writer.WriteStringValue(hyperLink.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(hyperLink); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index 5eee3c5bf..e5921d733 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IdCorrespondence = CDP4Common.DTO.IdCorrespondence; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalId", externalId => new JValue(externalId) }, - { "iid", iid => new JValue(iid) }, - { "internalThing", internalThing => new JValue(internalThing) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IdCorrespondence idCorrespondence) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), idCorrespondence.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](idCorrespondence.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](idCorrespondence.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalId", this.PropertySerializerMap["externalId"](idCorrespondence.ExternalId)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](idCorrespondence.Iid)); - jsonObject.Add("internalThing", this.PropertySerializerMap["internalThing"](idCorrespondence.InternalThing)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](idCorrespondence.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](idCorrespondence.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](idCorrespondence.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalid": + var allowedVersionsForExternalId = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalId.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalId"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "internalthing": + var allowedVersionsForInternalThing = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForInternalThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("internalThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IdCorrespondence"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not IdCorrespondence idCorrespondence) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); } - var idCorrespondence = thing as IdCorrespondence; - if (idCorrespondence == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a IdCorrespondence."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(idCorrespondence.Actor.HasValue) + { + writer.WriteStringValue(idCorrespondence.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(idCorrespondence); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index 092289767..ef20fd8f1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IndependentParameterTypeAssignment = CDP4Common.DTO.IndependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,390 @@ namespace CDP4JsonSerializer public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IndependentParameterTypeAssignment independentParameterTypeAssignment) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), independentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](independentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](independentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](independentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](independentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](independentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](independentParameterTypeAssignment.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + var allowedVersionsForMeasurementScale = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMeasurementScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IndependentParameterTypeAssignment"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); } - var independentParameterTypeAssignment = thing as IndependentParameterTypeAssignment; - if (independentParameterTypeAssignment == null) + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a IndependentParameterTypeAssignment."); + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(independentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(independentParameterTypeAssignment); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 1d4cd1f28..3dfd5bc22 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IntervalScale = CDP4Common.DTO.IntervalScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,97 +50,1022 @@ namespace CDP4JsonSerializer public class IntervalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IntervalScale intervalScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](intervalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), intervalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](intervalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](intervalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](intervalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](intervalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](intervalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](intervalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](intervalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](intervalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](intervalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](intervalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](intervalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](intervalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](intervalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](intervalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), intervalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](intervalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](intervalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](intervalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](intervalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](intervalScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](intervalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + var allowedVersionsForIsMaximumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + var allowedVersionsForIsMinimumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + var allowedVersionsForMappingToReferenceScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + var allowedVersionsForMaximumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + var allowedVersionsForMinimumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + var allowedVersionsForNegativeValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + var allowedVersionsForNumberSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + var allowedVersionsForPositiveValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not IntervalScale intervalScale) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); } - var intervalScale = thing as IntervalScale; - if (intervalScale == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a IntervalScale."); + Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(intervalScale.Actor.HasValue) + { + writer.WriteStringValue(intervalScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(intervalScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index 95bf1f9e6..618c3355b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Iteration = CDP4Common.DTO.Iteration; /// /// The purpose of the class is to provide a specific serializer @@ -44,107 +50,1525 @@ namespace CDP4JsonSerializer public class IterationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualFiniteStateList", actualFiniteStateList => new JArray(actualFiniteStateList) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOption", defaultOption => new JValue(defaultOption) }, - { "diagramCanvas", diagramCanvas => new JArray(diagramCanvas) }, - { "domainFileStore", domainFileStore => new JArray(domainFileStore) }, - { "element", element => new JArray(element) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalIdentifierMap", externalIdentifierMap => new JArray(externalIdentifierMap) }, - { "goal", goal => new JArray(goal) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JValue(iterationSetup) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "option", option => new JArray(((IEnumerable)option).Cast().Select(x => x.ToJsonObject())) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(possibleFiniteStateList) }, - { "publication", publication => new JArray(publication) }, - { "relationship", relationship => new JArray(relationship) }, - { "requirementsSpecification", requirementsSpecification => new JArray(requirementsSpecification) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerificationList", ruleVerificationList => new JArray(ruleVerificationList) }, - { "sharedDiagramStyle", sharedDiagramStyle => new JArray(sharedDiagramStyle) }, - { "sourceIterationIid", sourceIterationIid => new JValue(sourceIterationIid) }, - { "stakeholder", stakeholder => new JArray(stakeholder) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "stakeholderValueMap", stakeholderValueMap => new JArray(stakeholderValueMap) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topElement", topElement => new JValue(topElement) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Iteration iteration) - { - var jsonObject = new JObject(); - jsonObject.Add("actualFiniteStateList", this.PropertySerializerMap["actualFiniteStateList"](iteration.ActualFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iteration.ClassKind))); - jsonObject.Add("defaultOption", this.PropertySerializerMap["defaultOption"](iteration.DefaultOption)); - jsonObject.Add("diagramCanvas", this.PropertySerializerMap["diagramCanvas"](iteration.DiagramCanvas.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainFileStore", this.PropertySerializerMap["domainFileStore"](iteration.DomainFileStore.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("element", this.PropertySerializerMap["element"](iteration.Element.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iteration.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iteration.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalIdentifierMap", this.PropertySerializerMap["externalIdentifierMap"](iteration.ExternalIdentifierMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](iteration.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iteration.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](iteration.IterationSetup)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iteration.ModifiedOn)); - jsonObject.Add("option", this.PropertySerializerMap["option"](iteration.Option.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](iteration.PossibleFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("publication", this.PropertySerializerMap["publication"](iteration.Publication.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationship", this.PropertySerializerMap["relationship"](iteration.Relationship.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirementsSpecification", this.PropertySerializerMap["requirementsSpecification"](iteration.RequirementsSpecification.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iteration.RevisionNumber)); - jsonObject.Add("ruleVerificationList", this.PropertySerializerMap["ruleVerificationList"](iteration.RuleVerificationList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sharedDiagramStyle", this.PropertySerializerMap["sharedDiagramStyle"](iteration.SharedDiagramStyle.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sourceIterationIid", this.PropertySerializerMap["sourceIterationIid"](iteration.SourceIterationIid)); - jsonObject.Add("stakeholder", this.PropertySerializerMap["stakeholder"](iteration.Stakeholder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](iteration.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValueMap", this.PropertySerializerMap["stakeholderValueMap"](iteration.StakeholderValueMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iteration.ThingPreference)); - jsonObject.Add("topElement", this.PropertySerializerMap["topElement"](iteration.TopElement)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](iteration.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualfinitestatelist": + var allowedVersionsForActualFiniteStateList = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualFiniteStateList.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("actualFiniteStateList"u8); + + if(value is IEnumerable objectListActualFiniteStateList) + { + foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultoption": + var allowedVersionsForDefaultOption = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultOption.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramcanvas": + var allowedVersionsForDiagramCanvas = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiagramCanvas.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramCanvas"u8); + + if(value is IEnumerable objectListDiagramCanvas) + { + foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + } + + writer.WriteEndArray(); + break; + case "domainfilestore": + var allowedVersionsForDomainFileStore = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomainFileStore.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domainFileStore"u8); + + if(value is IEnumerable objectListDomainFileStore) + { + foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + } + + writer.WriteEndArray(); + break; + case "element": + var allowedVersionsForElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("element"u8); + + if(value is IEnumerable objectListElement) + { + foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalidentifiermap": + var allowedVersionsForExternalIdentifierMap = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExternalIdentifierMap.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("externalIdentifierMap"u8); + + if(value is IEnumerable objectListExternalIdentifierMap) + { + foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + } + + writer.WriteEndArray(); + break; + case "goal": + var allowedVersionsForGoal = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGoal.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("goal"u8); + + if(value is IEnumerable objectListGoal) + { + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + var allowedVersionsForIterationSetup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIterationSetup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "option": + var allowedVersionsForOption = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOption.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("option"u8); + + if(value is IEnumerable objectListOption) + { + foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + } + + writer.WriteEndArray(); + break; + case "possiblefinitestatelist": + var allowedVersionsForPossibleFiniteStateList = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleFiniteStateList.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "publication": + var allowedVersionsForPublication = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublication.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("publication"u8); + + if(value is IEnumerable objectListPublication) + { + foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + } + + writer.WriteEndArray(); + break; + case "relationship": + var allowedVersionsForRelationship = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelationship.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relationship"u8); + + if(value is IEnumerable objectListRelationship) + { + foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + } + + writer.WriteEndArray(); + break; + case "requirementsspecification": + var allowedVersionsForRequirementsSpecification = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequirementsSpecification.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirementsSpecification"u8); + + if(value is IEnumerable objectListRequirementsSpecification) + { + foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverificationlist": + var allowedVersionsForRuleVerificationList = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRuleVerificationList.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("ruleVerificationList"u8); + + if(value is IEnumerable objectListRuleVerificationList) + { + foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + } + + writer.WriteEndArray(); + break; + case "shareddiagramstyle": + var allowedVersionsForSharedDiagramStyle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSharedDiagramStyle.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sharedDiagramStyle"u8); + + if(value is IEnumerable objectListSharedDiagramStyle) + { + foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "sourceiterationiid": + var allowedVersionsForSourceIterationIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceIterationIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceIterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholder": + var allowedVersionsForStakeholder = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholder.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholder"u8); + + if(value is IEnumerable objectListStakeholder) + { + foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + } + + writer.WriteEndArray(); + break; + case "stakeholdervalue": + var allowedVersionsForStakeholderValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "stakeholdervaluemap": + var allowedVersionsForStakeholderValueMap = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholderValueMap.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValueMap"u8); + + if(value is IEnumerable objectListStakeholderValueMap) + { + foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topelement": + var allowedVersionsForTopElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTopElement.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("topElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + var allowedVersionsForValueGroup = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueGroup"u8); + + if(value is IEnumerable objectListValueGroup) + { + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Iteration iteration) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); } - var iteration = thing as Iteration; - if (iteration == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a Iteration."); + Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.0.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.1.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.2.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(iteration.Actor.HasValue) + { + writer.WriteStringValue(iteration.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(iteration); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index b3f98bd3b..5f6ab1369 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IterationSetup = CDP4Common.DTO.IterationSetup; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,668 @@ namespace CDP4JsonSerializer public class IterationSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "frozenOn", frozenOn => new JValue(frozenOn != null ? ((DateTime)frozenOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isDeleted", isDeleted => new JValue(isDeleted) }, - { "iterationIid", iterationIid => new JValue(iterationIid) }, - { "iterationNumber", iterationNumber => new JValue(iterationNumber) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sourceIterationSetup", sourceIterationSetup => new JValue(sourceIterationSetup) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IterationSetup iterationSetup) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iterationSetup.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](iterationSetup.CreatedOn)); - jsonObject.Add("description", this.PropertySerializerMap["description"](iterationSetup.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iterationSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iterationSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("frozenOn", this.PropertySerializerMap["frozenOn"](iterationSetup.FrozenOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iterationSetup.Iid)); - jsonObject.Add("isDeleted", this.PropertySerializerMap["isDeleted"](iterationSetup.IsDeleted)); - jsonObject.Add("iterationIid", this.PropertySerializerMap["iterationIid"](iterationSetup.IterationIid)); - jsonObject.Add("iterationNumber", this.PropertySerializerMap["iterationNumber"](iterationSetup.IterationNumber)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iterationSetup.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iterationSetup.RevisionNumber)); - jsonObject.Add("sourceIterationSetup", this.PropertySerializerMap["sourceIterationSetup"](iterationSetup.SourceIterationSetup)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iterationSetup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + var allowedVersionsForDescription = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDescription.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "frozenon": + var allowedVersionsForFrozenOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFrozenOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("frozenOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeleted": + var allowedVersionsForIsDeleted = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeleted.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeleted"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationiid": + var allowedVersionsForIterationIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIterationIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationnumber": + var allowedVersionsForIterationNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIterationNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceiterationsetup": + var allowedVersionsForSourceIterationSetup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceIterationSetup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceIterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IterationSetup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); + return; } - var iterationSetup = thing as IterationSetup; - if (iterationSetup == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a IterationSetup."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(iterationSetup.Actor.HasValue) + { + writer.WriteStringValue(iterationSetup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(iterationSetup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index fd2b705ac..75ef50fd7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LinearConversionUnit = CDP4Common.DTO.LinearConversionUnit; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,702 @@ namespace CDP4JsonSerializer public class LinearConversionUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LinearConversionUnit linearConversionUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](linearConversionUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), linearConversionUnit.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](linearConversionUnit.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](linearConversionUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](linearConversionUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](linearConversionUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](linearConversionUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](linearConversionUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](linearConversionUnit.Name)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](linearConversionUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](linearConversionUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](linearConversionUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](linearConversionUnit.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + var allowedVersionsForConversionFactor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForConversionFactor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + var allowedVersionsForReferenceUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LinearConversionUnit"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not LinearConversionUnit linearConversionUnit) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); } - var linearConversionUnit = thing as LinearConversionUnit; - if (linearConversionUnit == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a LinearConversionUnit."); + Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(linearConversionUnit.Actor.HasValue) + { + writer.WriteStringValue(linearConversionUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(linearConversionUnit); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index 637d9bbaa..bb2eb50c7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogEntryChangelogItem = CDP4Common.DTO.LogEntryChangelogItem; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,440 @@ namespace CDP4JsonSerializer public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedItemIid", affectedItemIid => new JValue(affectedItemIid) }, - { "affectedReferenceIid", affectedReferenceIid => new JArray(affectedReferenceIid) }, - { "changeDescription", changeDescription => new JValue(changeDescription) }, - { "changelogKind", changelogKind => new JValue(changelogKind.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LogEntryChangelogItem logEntryChangelogItem) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](logEntryChangelogItem.AffectedItemIid)); - jsonObject.Add("affectedReferenceIid", this.PropertySerializerMap["affectedReferenceIid"](logEntryChangelogItem.AffectedReferenceIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeDescription", this.PropertySerializerMap["changeDescription"](logEntryChangelogItem.ChangeDescription)); - jsonObject.Add("changelogKind", this.PropertySerializerMap["changelogKind"](Enum.GetName(typeof(CDP4Common.CommonData.LogEntryChangelogItemKind), logEntryChangelogItem.ChangelogKind))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logEntryChangelogItem.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logEntryChangelogItem.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logEntryChangelogItem.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logEntryChangelogItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logEntryChangelogItem.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteditemiid": + var allowedVersionsForAffectedItemIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("affectedItemIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affectedreferenceiid": + var allowedVersionsForAffectedReferenceIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedReferenceIid.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedReferenceIid"u8); + + if(value is IEnumerable objectListAffectedReferenceIid) + { + foreach(var affectedReferenceIidItem in objectListAffectedReferenceIid) + { + writer.WriteStringValue((Guid)affectedReferenceIidItem); + } + } + + writer.WriteEndArray(); + break; + case "changedescription": + var allowedVersionsForChangeDescription = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForChangeDescription.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeDescription"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "changelogkind": + var allowedVersionsForChangelogKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForChangelogKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changelogKind"u8); + + if(value != null) + { + writer.WriteStringValue(((LogEntryChangelogItemKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogEntryChangelogItem"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not LogEntryChangelogItem logEntryChangelogItem) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); } - var logEntryChangelogItem = thing as LogEntryChangelogItem; - if (logEntryChangelogItem == null) + if (requestedDataModelVersion < Version.Parse("1.2.0")) { - throw new InvalidOperationException("The thing is not a LogEntryChangelogItem."); + Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing LogEntryChangelogItem for Version 1.2.0"); + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing LogEntryChangelogItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logEntryChangelogItem.Actor.HasValue) + { + writer.WriteStringValue(logEntryChangelogItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(logEntryChangelogItem); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index fd9e8eb96..efd6a6ffa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogarithmicScale = CDP4Common.DTO.LogarithmicScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,107 +50,1216 @@ namespace CDP4JsonSerializer public class LogarithmicScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "factor", factor => new JValue(factor) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "logarithmBase", logarithmBase => new JValue(logarithmBase.ToString()) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "referenceQuantityKind", referenceQuantityKind => new JValue(referenceQuantityKind) }, - { "referenceQuantityValue", referenceQuantityValue => new JArray(referenceQuantityValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LogarithmicScale logarithmicScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](logarithmicScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logarithmicScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](logarithmicScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logarithmicScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logarithmicScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](logarithmicScale.Exponent)); - jsonObject.Add("factor", this.PropertySerializerMap["factor"](logarithmicScale.Factor)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](logarithmicScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logarithmicScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](logarithmicScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](logarithmicScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](logarithmicScale.IsMinimumInclusive)); - jsonObject.Add("logarithmBase", this.PropertySerializerMap["logarithmBase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.LogarithmBaseKind), logarithmicScale.LogarithmBase))); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](logarithmicScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](logarithmicScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logarithmicScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](logarithmicScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](logarithmicScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), logarithmicScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](logarithmicScale.PositiveValueConnotation)); - jsonObject.Add("referenceQuantityKind", this.PropertySerializerMap["referenceQuantityKind"](logarithmicScale.ReferenceQuantityKind)); - jsonObject.Add("referenceQuantityValue", this.PropertySerializerMap["referenceQuantityValue"](logarithmicScale.ReferenceQuantityValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logarithmicScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](logarithmicScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logarithmicScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](logarithmicScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](logarithmicScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + var allowedVersionsForExponent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExponent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "factor": + var allowedVersionsForFactor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFactor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("factor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + var allowedVersionsForIsMaximumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + var allowedVersionsForIsMinimumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logarithmbase": + var allowedVersionsForLogarithmBase = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLogarithmBase.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("logarithmBase"u8); + + if(value != null) + { + writer.WriteStringValue(((LogarithmBaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + var allowedVersionsForMappingToReferenceScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + var allowedVersionsForMaximumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + var allowedVersionsForMinimumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + var allowedVersionsForNegativeValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + var allowedVersionsForNumberSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + var allowedVersionsForPositiveValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantitykind": + var allowedVersionsForReferenceQuantityKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceQuantityKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceQuantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantityvalue": + var allowedVersionsForReferenceQuantityValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceQuantityValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceQuantityValue"u8); + + if(value is IEnumerable objectListReferenceQuantityValue) + { + foreach(var referenceQuantityValueItem in objectListReferenceQuantityValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogarithmicScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); + return; } - var logarithmicScale = thing as LogarithmicScale; - if (logarithmicScale == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a LogarithmicScale."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logarithmicScale.Actor.HasValue) + { + writer.WriteStringValue(logarithmicScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(logarithmicScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index 6e2726cf5..f5cc23eec 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MappingToReferenceScale = CDP4Common.DTO.MappingToReferenceScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "dependentScaleValue", dependentScaleValue => new JValue(dependentScaleValue) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referenceScaleValue", referenceScaleValue => new JValue(referenceScaleValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MappingToReferenceScale mappingToReferenceScale) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), mappingToReferenceScale.ClassKind))); - jsonObject.Add("dependentScaleValue", this.PropertySerializerMap["dependentScaleValue"](mappingToReferenceScale.DependentScaleValue)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](mappingToReferenceScale.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](mappingToReferenceScale.ModifiedOn)); - jsonObject.Add("referenceScaleValue", this.PropertySerializerMap["referenceScaleValue"](mappingToReferenceScale.ReferenceScaleValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](mappingToReferenceScale.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](mappingToReferenceScale.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "dependentscalevalue": + var allowedVersionsForDependentScaleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDependentScaleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("dependentScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencescalevalue": + var allowedVersionsForReferenceScaleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceScaleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MappingToReferenceScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not MappingToReferenceScale mappingToReferenceScale) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); } - var mappingToReferenceScale = thing as MappingToReferenceScale; - if (mappingToReferenceScale == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a MappingToReferenceScale."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(mappingToReferenceScale.Actor.HasValue) + { + writer.WriteStringValue(mappingToReferenceScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(mappingToReferenceScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index 7530df8fc..39cf32199 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelLogEntry = CDP4Common.DTO.ModelLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,778 @@ namespace CDP4JsonSerializer public class ModelLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModelLogEntry modelLogEntry) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](modelLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](modelLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](modelLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](modelLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](modelLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](modelLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](modelLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), modelLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelLogEntry.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteddomainiid": + var allowedVersionsForAffectedDomainIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedDomainIid.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) + { + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + } + + writer.WriteEndArray(); + break; + case "affecteditemiid": + var allowedVersionsForAffectedItemIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedItemIid"u8); + + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + var allowedVersionsForLevel = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLevel.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + var allowedVersionsForLogEntryChangelogItem = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLogEntryChangelogItem.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntryChangelogItem"u8); + + if(value is IEnumerable objectListLogEntryChangelogItem) + { + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelLogEntry"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); + return; } - var modelLogEntry = thing as ModelLogEntry; - if (modelLogEntry == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ModelLogEntry."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelLogEntry.Actor.HasValue) + { + writer.WriteStringValue(modelLogEntry.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(modelLogEntry); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 7819baeda..adee5fa3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelReferenceDataLibrary = CDP4Common.DTO.ModelReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -44,101 +50,1366 @@ namespace CDP4JsonSerializer public class ModelReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModelReferenceDataLibrary modelReferenceDataLibrary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](modelReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](modelReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](modelReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](modelReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelReferenceDataLibrary.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](modelReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](modelReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](modelReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](modelReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](modelReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](modelReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "basequantitykind": + var allowedVersionsForBaseQuantityKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBaseQuantityKind.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseQuantityKind"u8); + + if(value is IEnumerable objectListBaseQuantityKind) + { + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + } + + writer.WriteEndArray(); + break; + case "baseunit": + var allowedVersionsForBaseUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBaseUnit.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseUnit"u8); + + if(value is IEnumerable objectListBaseUnit) + { + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + var allowedVersionsForConstant = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForConstant.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + + writer.WriteEndArray(); + break; + case "definedcategory": + var allowedVersionsForDefinedCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinedCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definedCategory"u8); + + if(value is IEnumerable objectListDefinedCategory) + { + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + var allowedVersionsForFileType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFileType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "glossary": + var allowedVersionsForGlossary = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGlossary.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("glossary"u8); + + if(value is IEnumerable objectListGlossary) + { + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "referencesource": + var allowedVersionsForReferenceSource = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceSource.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceSource"u8); + + if(value is IEnumerable objectListReferenceSource) + { + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + var allowedVersionsForRequiredRdl = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + var allowedVersionsForRule = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRule.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("rule"u8); + + if(value is IEnumerable objectListRule) + { + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + } + + writer.WriteEndArray(); + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("scale"u8); + + if(value is IEnumerable objectListScale) + { + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unit"u8); + + if(value is IEnumerable objectListUnit) + { + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + } + + writer.WriteEndArray(); + break; + case "unitprefix": + var allowedVersionsForUnitPrefix = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnitPrefix.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitPrefix"u8); + + if(value is IEnumerable objectListUnitPrefix) + { + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); + return; } - var modelReferenceDataLibrary = thing as ModelReferenceDataLibrary; - if (modelReferenceDataLibrary == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ModelReferenceDataLibrary."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(modelReferenceDataLibrary); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index b38844db1..35e0bb8a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModellingThingReference = CDP4Common.DTO.ModellingThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,408 @@ namespace CDP4JsonSerializer public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModellingThingReference modellingThingReference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modellingThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modellingThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modellingThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modellingThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modellingThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](modellingThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](modellingThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modellingThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modellingThingReference.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedrevisionnumber": + var allowedVersionsForReferencedRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + var allowedVersionsForReferencedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModellingThingReference"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ModellingThingReference modellingThingReference) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); } - var modellingThingReference = thing as ModellingThingReference; - if (modellingThingReference == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ModellingThingReference."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modellingThingReference.Actor.HasValue) + { + writer.WriteStringValue(modellingThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(modellingThingReference); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index 9b29a1990..d00ea6336 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationshipRule = CDP4Common.DTO.MultiRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,794 @@ namespace CDP4JsonSerializer public class MultiRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxRelated", maxRelated => new JValue(maxRelated) }, - { "minRelated", minRelated => new JValue(minRelated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relatedCategory", relatedCategory => new JArray(relatedCategory) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationshipRule multiRelationshipRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](multiRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](multiRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](multiRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationshipRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](multiRelationshipRule.IsDeprecated)); - jsonObject.Add("maxRelated", this.PropertySerializerMap["maxRelated"](multiRelationshipRule.MaxRelated)); - jsonObject.Add("minRelated", this.PropertySerializerMap["minRelated"](multiRelationshipRule.MinRelated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationshipRule.Name)); - jsonObject.Add("relatedCategory", this.PropertySerializerMap["relatedCategory"](multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](multiRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](multiRelationshipRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationshipRule.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxrelated": + var allowedVersionsForMaxRelated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaxRelated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minrelated": + var allowedVersionsForMinRelated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinRelated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedcategory": + var allowedVersionsForRelatedCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedCategory"u8); + + if(value is IEnumerable objectListRelatedCategory) + { + foreach(var relatedCategoryItem in objectListRelatedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "relationshipcategory": + var allowedVersionsForRelationshipCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelationshipCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationshipRule"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); + return; } - var multiRelationshipRule = thing as MultiRelationshipRule; - if (multiRelationshipRule == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a MultiRelationshipRule."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationshipRule.Actor.HasValue) + { + writer.WriteStringValue(multiRelationshipRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(multiRelationshipRule); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 74ec82d50..fb3357b34 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationship = CDP4Common.DTO.MultiRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,585 @@ namespace CDP4JsonSerializer public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationship multiRelationship) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](multiRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](multiRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](multiRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](multiRelationship.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationship.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationship.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + var allowedVersionsForParameterValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationship"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not MultiRelationship multiRelationship) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); } - var multiRelationship = thing as MultiRelationship; - if (multiRelationship == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a MultiRelationship."); + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationship.Actor.HasValue) + { + writer.WriteStringValue(multiRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(multiRelationship); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index e13e93737..6c4ddc067 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NaturalLanguage = CDP4Common.DTO.NaturalLanguage; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nativeName", nativeName => new JValue(nativeName) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NaturalLanguage naturalLanguage) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), naturalLanguage.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](naturalLanguage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](naturalLanguage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](naturalLanguage.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](naturalLanguage.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](naturalLanguage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](naturalLanguage.Name)); - jsonObject.Add("nativeName", this.PropertySerializerMap["nativeName"](naturalLanguage.NativeName)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](naturalLanguage.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](naturalLanguage.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nativename": + var allowedVersionsForNativeName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNativeName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("nativeName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NaturalLanguage"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); + return; } - var naturalLanguage = thing as NaturalLanguage; - if (naturalLanguage == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a NaturalLanguage."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(naturalLanguage.Actor.HasValue) + { + writer.WriteStringValue(naturalLanguage.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(naturalLanguage); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 29cf24e9d..25f580cc5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedElement = CDP4Common.DTO.NestedElement; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,542 @@ namespace CDP4JsonSerializer public class NestedElementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "elementUsage", elementUsage => new JArray(((IEnumerable)elementUsage).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "nestedParameter", nestedParameter => new JArray(nestedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rootElement", rootElement => new JValue(rootElement) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NestedElement nestedElement) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedElement.ClassKind))); - jsonObject.Add("elementUsage", this.PropertySerializerMap["elementUsage"](nestedElement.ElementUsage.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedElement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedElement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedElement.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedElement.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedElement.ModifiedOn)); - jsonObject.Add("nestedParameter", this.PropertySerializerMap["nestedParameter"](nestedElement.NestedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedElement.RevisionNumber)); - jsonObject.Add("rootElement", this.PropertySerializerMap["rootElement"](nestedElement.RootElement)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedElement.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "elementusage": + var allowedVersionsForElementUsage = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForElementUsage.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("elementUsage"u8); + + if(value is IEnumerable objectListElementUsage) + { + foreach(var elementUsageItem in objectListElementUsage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + var allowedVersionsForIsVolatile = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsVolatile.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nestedparameter": + var allowedVersionsForNestedParameter = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNestedParameter.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("nestedParameter"u8); + + if(value is IEnumerable objectListNestedParameter) + { + foreach(var nestedParameterItem in objectListNestedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rootelement": + var allowedVersionsForRootElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRootElement.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("rootElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedElement"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not NestedElement nestedElement) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); } - var nestedElement = thing as NestedElement; - if (nestedElement == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a NestedElement."); + Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedElement.Actor.HasValue) + { + writer.WriteStringValue(nestedElement.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(nestedElement); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index e77c2355e..a2599bba9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedParameter = CDP4Common.DTO.NestedParameter; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,598 @@ namespace CDP4JsonSerializer public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JValue(actualState) }, - { "actualValue", actualValue => new JValue(actualValue) }, - { "associatedParameter", associatedParameter => new JValue(associatedParameter) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(formula) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NestedParameter nestedParameter) - { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](nestedParameter.ActualState)); - jsonObject.Add("actualValue", this.PropertySerializerMap["actualValue"](nestedParameter.ActualValue)); - jsonObject.Add("associatedParameter", this.PropertySerializerMap["associatedParameter"](nestedParameter.AssociatedParameter)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedParameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedParameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedParameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](nestedParameter.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedParameter.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedParameter.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedParameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](nestedParameter.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedParameter.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedParameter.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + var allowedVersionsForActualState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualState.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualvalue": + var allowedVersionsForActualValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "associatedparameter": + var allowedVersionsForAssociatedParameter = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAssociatedParameter.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("associatedParameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + var allowedVersionsForFormula = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFormula.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("formula"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + var allowedVersionsForIsVolatile = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsVolatile.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedParameter"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not NestedParameter nestedParameter) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); } - var nestedParameter = thing as NestedParameter; - if (nestedParameter == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a NestedParameter."); + Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.0.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.1.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.2.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedParameter.Actor.HasValue) + { + writer.WriteStringValue(nestedParameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(nestedParameter); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 72bc8ad78..46c14ccad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NotExpression = CDP4Common.DTO.NotExpression; /// /// The purpose of the class is to provide a specific serializer @@ -44,67 +50,392 @@ namespace CDP4JsonSerializer public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JValue(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NotExpression notExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), notExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](notExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](notExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](notExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](notExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](notExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](notExpression.Term)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](notExpression.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + var allowedVersionsForTerm = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTerm.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("term"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NotExpression"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not NotExpression notExpression) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); } - var notExpression = thing as NotExpression; - if (notExpression == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a NotExpression."); + Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(notExpression.Actor.HasValue) + { + writer.WriteStringValue(notExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(notExpression); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index b0aac8817..2dbb091a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Option = CDP4Common.DTO.Option; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,716 @@ namespace CDP4JsonSerializer public class OptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nestedElement", nestedElement => new JArray(nestedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Option option) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](option.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](option.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), option.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](option.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](option.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](option.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](option.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](option.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](option.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](option.Name)); - jsonObject.Add("nestedElement", this.PropertySerializerMap["nestedElement"](option.NestedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](option.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](option.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](option.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nestedelement": + var allowedVersionsForNestedElement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNestedElement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("nestedElement"u8); + + if(value is IEnumerable objectListNestedElement) + { + foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Option"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); + return; } - var option = thing as Option; - if (option == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Option."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(option.Actor.HasValue) + { + writer.WriteStringValue(option.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(option); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index d9b03f282..923a18674 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrExpression = CDP4Common.DTO.OrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -44,67 +50,416 @@ namespace CDP4JsonSerializer public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrExpression orExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), orExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](orExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](orExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](orExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](orExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](orExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](orExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](orExpression.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + var allowedVersionsForTerm = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTerm.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrExpression"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); + return; } - var orExpression = thing as OrExpression; - if (orExpression == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a OrExpression."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(orExpression.Actor.HasValue) + { + writer.WriteStringValue(orExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(orExpression); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 06617a650..621dc57aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrdinalScale = CDP4Common.DTO.OrdinalScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,99 +50,1056 @@ namespace CDP4JsonSerializer public class OrdinalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "useShortNameValues", useShortNameValues => new JValue(useShortNameValues) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrdinalScale ordinalScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ordinalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ordinalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ordinalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ordinalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ordinalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ordinalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ordinalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ordinalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ordinalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ordinalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ordinalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ordinalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ordinalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ordinalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ordinalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ordinalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ordinalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ordinalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ordinalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ordinalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ordinalScale.Unit)); - jsonObject.Add("useShortNameValues", this.PropertySerializerMap["useShortNameValues"](ordinalScale.UseShortNameValues)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ordinalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + var allowedVersionsForIsMaximumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + var allowedVersionsForIsMinimumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + var allowedVersionsForMappingToReferenceScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + var allowedVersionsForMaximumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + var allowedVersionsForMinimumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + var allowedVersionsForNegativeValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + var allowedVersionsForNumberSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + var allowedVersionsForPositiveValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "useshortnamevalues": + var allowedVersionsForUseShortNameValues = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUseShortNameValues.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("useShortNameValues"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrdinalScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not OrdinalScale ordinalScale) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); } - var ordinalScale = thing as OrdinalScale; - if (ordinalScale == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a OrdinalScale."); + Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ordinalScale.Actor.HasValue) + { + writer.WriteStringValue(ordinalScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(ordinalScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 82eb0eff5..9a6f7b740 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Organization = CDP4Common.DTO.Organization; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class OrganizationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Organization organization) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organization.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organization.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organization.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organization.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](organization.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organization.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](organization.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organization.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](organization.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organization.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Organization"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); + return; } - var organization = thing as Organization; - if (organization == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Organization."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organization.Actor.HasValue) + { + writer.WriteStringValue(organization.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(organization); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 5c243593b..a5664db18 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrganizationalParticipant = CDP4Common.DTO.OrganizationalParticipant; /// /// The purpose of the class is to provide a specific serializer @@ -44,67 +50,344 @@ namespace CDP4JsonSerializer public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrganizationalParticipant organizationalParticipant) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organizationalParticipant.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organizationalParticipant.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organizationalParticipant.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](organizationalParticipant.Organization)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organizationalParticipant.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organizationalParticipant.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + var allowedVersionsForOrganization = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganization.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrganizationalParticipant"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not OrganizationalParticipant organizationalParticipant) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); } - var organizationalParticipant = thing as OrganizationalParticipant; - if (organizationalParticipant == null) + if (requestedDataModelVersion < Version.Parse("1.2.0")) { - throw new InvalidOperationException("The thing is not a OrganizationalParticipant."); + Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing OrganizationalParticipant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing OrganizationalParticipant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organizationalParticipant.Actor.HasValue) + { + writer.WriteStringValue(organizationalParticipant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(organizationalParticipant); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 89b636826..ceb911321 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OwnedStyle = CDP4Common.DTO.OwnedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -44,93 +50,1095 @@ namespace CDP4JsonSerializer public class OwnedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OwnedStyle ownedStyle) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ownedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ownedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ownedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](ownedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](ownedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](ownedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](ownedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](ownedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](ownedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](ownedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](ownedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](ownedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ownedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ownedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ownedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ownedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](ownedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](ownedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](ownedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ownedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](ownedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + var allowedVersionsForFillColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFillColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + var allowedVersionsForFillOpacity = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFillOpacity.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontbold": + var allowedVersionsForFontBold = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontBold.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + var allowedVersionsForFontColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontitalic": + var allowedVersionsForFontItalic = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontItalic.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + var allowedVersionsForFontName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + var allowedVersionsForFontSize = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontSize.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + var allowedVersionsForFontStrokeThrough = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontStrokeThrough.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + var allowedVersionsForFontUnderline = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontUnderline.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + var allowedVersionsForStrokeColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + var allowedVersionsForStrokeOpacity = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeOpacity.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + var allowedVersionsForStrokeWidth = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeWidth.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + var allowedVersionsForUsedColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUsedColor.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("usedColor"u8); + + if(value is IEnumerable objectListUsedColor) + { + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not OwnedStyle ownedStyle) + { + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); + return; } - var ownedStyle = thing as OwnedStyle; - if (ownedStyle == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a OwnedStyle."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ownedStyle.Actor.HasValue) + { + writer.WriteStringValue(ownedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(ownedStyle); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index 7b64c8b86..cef6bb6db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Page = CDP4Common.DTO.Page; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,568 @@ namespace CDP4JsonSerializer public class PageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Page page) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](page.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), page.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](page.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](page.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](page.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](page.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](page.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](page.Name)); - jsonObject.Add("note", this.PropertySerializerMap["note"](page.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](page.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](page.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](page.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](page.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + var allowedVersionsForNote = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNote.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("note"u8); + + if(value is IEnumerable objectListNote) + { + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + } + + writer.WriteEndArray(); + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Page"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Page page) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Page", nameof(thing)); } - var page = thing as Page; - if (page == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a Page."); + Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(page.Actor.HasValue) + { + writer.WriteStringValue(page.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(page); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index 35afbca65..d2bb26180 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterGroup = CDP4Common.DTO.ParameterGroup; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,462 @@ namespace CDP4JsonSerializer public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingGroup", containingGroup => new JValue(containingGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterGroup parameterGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterGroup.ClassKind))); - jsonObject.Add("containingGroup", this.PropertySerializerMap["containingGroup"](parameterGroup.ContainingGroup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterGroup.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterGroup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containinggroup": + var allowedVersionsForContainingGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContainingGroup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingGroup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterGroup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); + return; } - var parameterGroup = thing as ParameterGroup; - if (parameterGroup == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParameterGroup."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterGroup.Actor.HasValue) + { + writer.WriteStringValue(parameterGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterGroup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 8b5e7424a..7746b5d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverride = CDP4Common.DTO.ParameterOverride; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,542 @@ namespace CDP4JsonSerializer public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JValue(parameter) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverride parameterOverride) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverride.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverride.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverride.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverride.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverride.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterOverride.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](parameterOverride.Parameter)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameterOverride.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverride.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverride.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterOverride.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + var allowedVersionsForParameter = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameter.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + var allowedVersionsForParameterSubscription = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterSubscription.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterSubscription"u8); + + if(value is IEnumerable objectListParameterSubscription) + { + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + var allowedVersionsForValueSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSet.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverride"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterOverride parameterOverride) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); } - var parameterOverride = thing as ParameterOverride; - if (parameterOverride == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ParameterOverride."); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverride.Actor.HasValue) + { + writer.WriteStringValue(parameterOverride.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterOverride); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 71f0c2ff0..2cfd1c470 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverrideValueSet = CDP4Common.DTO.ParameterOverrideValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,526 @@ namespace CDP4JsonSerializer public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterValueSet", parameterValueSet => new JValue(parameterValueSet) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverrideValueSet parameterOverrideValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverrideValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterOverrideValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterOverrideValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverrideValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterOverrideValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverrideValueSet.ModifiedOn)); - jsonObject.Add("parameterValueSet", this.PropertySerializerMap["parameterValueSet"](parameterOverrideValueSet.ParameterValueSet)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterOverrideValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterOverrideValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverrideValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverrideValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterOverrideValueSet.ValueSwitch))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + var allowedVersionsForComputed = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForComputed.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + var allowedVersionsForFormula = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFormula.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + var allowedVersionsForManual = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForManual.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalueset": + var allowedVersionsForParameterValueSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValueSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + var allowedVersionsForPublished = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublished.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + var allowedVersionsForReference = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReference.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + var allowedVersionsForValueSwitch = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverrideValueSet"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); } - var parameterOverrideValueSet = thing as ParameterOverrideValueSet; - if (parameterOverrideValueSet == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ParameterOverrideValueSet."); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverrideValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterOverrideValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterOverrideValueSet); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index a2bbf5247..e9929f62a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Parameter = CDP4Common.DTO.Parameter; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,924 @@ namespace CDP4JsonSerializer public class ParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "allowDifferentOwnerOfOverride", allowDifferentOwnerOfOverride => new JValue(allowDifferentOwnerOfOverride) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expectsOverride", expectsOverride => new JValue(expectsOverride) }, - { "group", group => new JValue(group) }, - { "iid", iid => new JValue(iid) }, - { "isOptionDependent", isOptionDependent => new JValue(isOptionDependent) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "requestedBy", requestedBy => new JValue(requestedBy) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "stateDependence", stateDependence => new JValue(stateDependence) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Parameter parameter) - { - var jsonObject = new JObject(); - jsonObject.Add("allowDifferentOwnerOfOverride", this.PropertySerializerMap["allowDifferentOwnerOfOverride"](parameter.AllowDifferentOwnerOfOverride)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expectsOverride", this.PropertySerializerMap["expectsOverride"](parameter.ExpectsOverride)); - jsonObject.Add("group", this.PropertySerializerMap["group"](parameter.Group)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameter.Iid)); - jsonObject.Add("isOptionDependent", this.PropertySerializerMap["isOptionDependent"](parameter.IsOptionDependent)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameter.Owner)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameter.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameter.ParameterType)); - jsonObject.Add("requestedBy", this.PropertySerializerMap["requestedBy"](parameter.RequestedBy)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameter.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameter.Scale)); - jsonObject.Add("stateDependence", this.PropertySerializerMap["stateDependence"](parameter.StateDependence)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameter.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameter.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "allowdifferentownerofoverride": + var allowedVersionsForAllowDifferentOwnerOfOverride = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAllowDifferentOwnerOfOverride.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expectsoverride": + var allowedVersionsForExpectsOverride = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExpectsOverride.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("expectsOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "group": + var allowedVersionsForGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGroup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isoptiondependent": + var allowedVersionsForIsOptionDependent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsOptionDependent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isOptionDependent"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + var allowedVersionsForParameterSubscription = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterSubscription.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterSubscription"u8); + + if(value is IEnumerable objectListParameterSubscription) + { + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + } + + writer.WriteEndArray(); + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requestedby": + var allowedVersionsForRequestedBy = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequestedBy.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requestedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "statedependence": + var allowedVersionsForStateDependence = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStateDependence.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("stateDependence"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + var allowedVersionsForValueSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSet.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Parameter parameter) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); } - var parameter = thing as Parameter; - if (parameter == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a Parameter."); + Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.0.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.1.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.2.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameter.Actor.HasValue) + { + writer.WriteStringValue(parameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameter); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 392720421..31ec83387 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscription = CDP4Common.DTO.ParameterSubscription; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,450 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscription parameterSubscription) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscription.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscription.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscription.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscription.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscription.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterSubscription.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscription.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscription.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterSubscription.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + var allowedVersionsForValueSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSet.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscription"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); + return; } - var parameterSubscription = thing as ParameterSubscription; - if (parameterSubscription == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParameterSubscription."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscription.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscription.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterSubscription); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index a2a9afc19..3234ca5c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscriptionValueSet = CDP4Common.DTO.ParameterSubscriptionValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,446 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "subscribedValueSet", subscribedValueSet => new JValue(subscribedValueSet) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscriptionValueSet parameterSubscriptionValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscriptionValueSet.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscriptionValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterSubscriptionValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscriptionValueSet.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscriptionValueSet.RevisionNumber)); - jsonObject.Add("subscribedValueSet", this.PropertySerializerMap["subscribedValueSet"](parameterSubscriptionValueSet.SubscribedValueSet)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscriptionValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterSubscriptionValueSet.ValueSwitch))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + var allowedVersionsForManual = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForManual.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "subscribedvalueset": + var allowedVersionsForSubscribedValueSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSubscribedValueSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("subscribedValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + var allowedVersionsForValueSwitch = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscriptionValueSet"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); } - var parameterSubscriptionValueSet = thing as ParameterSubscriptionValueSet; - if (parameterSubscriptionValueSet == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParameterSubscriptionValueSet."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscriptionValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscriptionValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterSubscriptionValueSet); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 71a29a208..173e8bc3a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterTypeComponent = CDP4Common.DTO.ParameterTypeComponent; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,496 @@ namespace CDP4JsonSerializer public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterTypeComponent parameterTypeComponent) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterTypeComponent.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterTypeComponent.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterTypeComponent.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterTypeComponent.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterTypeComponent.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameterTypeComponent.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterTypeComponent.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterTypeComponent.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterTypeComponent"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterTypeComponent parameterTypeComponent) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); } - var parameterTypeComponent = thing as ParameterTypeComponent; - if (parameterTypeComponent == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ParameterTypeComponent."); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterTypeComponent.Actor.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterTypeComponent); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 1bb18011f..6ffcd74d7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterValueSet = CDP4Common.DTO.ParameterValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,632 @@ namespace CDP4JsonSerializer public class ParameterValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualOption", actualOption => new JValue(actualOption) }, - { "actualState", actualState => new JValue(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterValueSet parameterValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("actualOption", this.PropertySerializerMap["actualOption"](parameterValueSet.ActualOption)); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](parameterValueSet.ActualState)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterValueSet.ModifiedOn)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterValueSet.ValueSwitch))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualoption": + var allowedVersionsForActualOption = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualOption.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + var allowedVersionsForActualState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForActualState.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + var allowedVersionsForComputed = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForComputed.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + var allowedVersionsForFormula = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFormula.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + var allowedVersionsForManual = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForManual.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + var allowedVersionsForPublished = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublished.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + var allowedVersionsForReference = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReference.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + var allowedVersionsForValueSwitch = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterValueSet"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterValueSet parameterValueSet) + { + throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); + return; } - var parameterValueSet = thing as ParameterValueSet; - if (parameterValueSet == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParameterValueSet."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.0.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.1.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.2.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterValueSet); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index 319c10ea9..b300a61d0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterizedCategoryRule = CDP4Common.DTO.ParameterizedCategoryRule; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class ParameterizedCategoryRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JValue(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterizedCategoryRule parameterizedCategoryRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](parameterizedCategoryRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](parameterizedCategoryRule.Category)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterizedCategoryRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](parameterizedCategoryRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterizedCategoryRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](parameterizedCategoryRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterizedCategoryRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterizedCategoryRule.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterizedCategoryRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterizedCategoryRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterizedCategoryRule.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("category"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterizedCategoryRule"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); } - var parameterizedCategoryRule = thing as ParameterizedCategoryRule; - if (parameterizedCategoryRule == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParameterizedCategoryRule."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterizedCategoryRule.Actor.HasValue) + { + writer.WriteStringValue(parameterizedCategoryRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parameterizedCategoryRule); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index a7b92c322..767379e48 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParametricConstraint = CDP4Common.DTO.ParametricConstraint; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,486 @@ namespace CDP4JsonSerializer public class ParametricConstraintSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expression", expression => new JArray(expression) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topExpression", topExpression => new JValue(topExpression) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParametricConstraint parametricConstraint) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parametricConstraint.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parametricConstraint.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parametricConstraint.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expression", this.PropertySerializerMap["expression"](parametricConstraint.Expression.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parametricConstraint.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parametricConstraint.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parametricConstraint.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parametricConstraint.ThingPreference)); - jsonObject.Add("topExpression", this.PropertySerializerMap["topExpression"](parametricConstraint.TopExpression)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expression": + var allowedVersionsForExpression = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExpression.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("expression"u8); + + if(value is IEnumerable objectListExpression) + { + foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topexpression": + var allowedVersionsForTopExpression = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTopExpression.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("topExpression"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParametricConstraint"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParametricConstraint parametricConstraint) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); } - var parametricConstraint = thing as ParametricConstraint; - if (parametricConstraint == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ParametricConstraint."); + Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parametricConstraint.Actor.HasValue) + { + writer.WriteStringValue(parametricConstraint.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(parametricConstraint); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index 0ce446fdb..d3241fb99 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantPermission = CDP4Common.DTO.ParticipantPermission; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParticipantPermission participantPermission) - { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.ParticipantAccessRightKind), participantPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantPermission.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "accessright": + var allowedVersionsForAccessRight = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForAccessRight.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((ParticipantAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; + + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + var allowedVersionsForObjectClass = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForObjectClass.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantPermission"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); + return; } - var participantPermission = thing as ParticipantPermission; - if (participantPermission == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ParticipantPermission."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(participantPermission.Actor.HasValue) + { + writer.WriteStringValue(participantPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(participantPermission); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index e55db07f1..8d97e9a73 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantRole = CDP4Common.DTO.ParticipantRole; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class ParticipantRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "participantPermission", participantPermission => new JArray(participantPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParticipantRole participantRole) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](participantRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](participantRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](participantRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](participantRole.Name)); - jsonObject.Add("participantPermission", this.PropertySerializerMap["participantPermission"](participantRole.ParticipantPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](participantRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantRole.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "participantpermission": + var allowedVersionsForParticipantPermission = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParticipantPermission.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participantPermission"u8); + + if(value is IEnumerable objectListParticipantPermission) + { + foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantRole"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ParticipantRole participantRole) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); } - var participantRole = thing as ParticipantRole; - if (participantRole == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a ParticipantRole."); + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participantRole.Actor.HasValue) + { + writer.WriteStringValue(participantRole.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(participantRole); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index f00f210c1..e178a731d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Participant = CDP4Common.DTO.Participant; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,552 @@ namespace CDP4JsonSerializer public class ParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "person", person => new JValue(person) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "selectedDomain", selectedDomain => new JValue(selectedDomain) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Participant participant) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participant.ClassKind))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](participant.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participant.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](participant.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participant.ModifiedOn)); - jsonObject.Add("person", this.PropertySerializerMap["person"](participant.Person)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participant.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](participant.Role)); - jsonObject.Add("selectedDomain", this.PropertySerializerMap["selectedDomain"](participant.SelectedDomain)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participant.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + var allowedVersionsForDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + var allowedVersionsForIsActive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsActive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "person": + var allowedVersionsForPerson = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPerson.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("person"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + var allowedVersionsForRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRole.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "selecteddomain": + var allowedVersionsForSelectedDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSelectedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("selectedDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Participant"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Participant participant) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); } - var participant = thing as Participant; - if (participant == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Participant."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participant.Actor.HasValue) + { + writer.WriteStringValue(participant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(participant); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index 6eb3d7494..d253e3ace 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonPermission = CDP4Common.DTO.PersonPermission; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,460 @@ namespace CDP4JsonSerializer public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PersonPermission personPermission) - { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.PersonAccessRightKind), personPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personPermission.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "accessright": + var allowedVersionsForAccessRight = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForAccessRight.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((PersonAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; + + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + var allowedVersionsForObjectClass = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForObjectClass.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonPermission"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); + return; } - var personPermission = thing as PersonPermission; - if (personPermission == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a PersonPermission."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(personPermission.Actor.HasValue) + { + writer.WriteStringValue(personPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(personPermission); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index dd4e35b4b..6fecd76eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonRole = CDP4Common.DTO.PersonRole; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class PersonRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "personPermission", personPermission => new JArray(personPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PersonRole personRole) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](personRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](personRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](personRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](personRole.Name)); - jsonObject.Add("personPermission", this.PropertySerializerMap["personPermission"](personRole.PersonPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](personRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personRole.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "personpermission": + var allowedVersionsForPersonPermission = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPersonPermission.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("personPermission"u8); + + if(value is IEnumerable objectListPersonPermission) + { + foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonRole"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not PersonRole personRole) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); } - var personRole = thing as PersonRole; - if (personRole == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a PersonRole."); + Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(personRole.Actor.HasValue) + { + writer.WriteStringValue(personRole.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(personRole); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index 477319e50..632571c77 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Person = CDP4Common.DTO.Person; /// /// The purpose of the class is to provide a specific serializer @@ -44,95 +50,1120 @@ namespace CDP4JsonSerializer public class PersonSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultDomain", defaultDomain => new JValue(defaultDomain) }, - { "defaultEmailAddress", defaultEmailAddress => new JValue(defaultEmailAddress) }, - { "defaultTelephoneNumber", defaultTelephoneNumber => new JValue(defaultTelephoneNumber) }, - { "emailAddress", emailAddress => new JArray(emailAddress) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "givenName", givenName => new JValue(givenName) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "organizationalUnit", organizationalUnit => new JValue(organizationalUnit) }, - { "password", password => new JValue(password) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "shortName", shortName => new JValue(shortName) }, - { "surname", surname => new JValue(surname) }, - { "telephoneNumber", telephoneNumber => new JArray(telephoneNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "userPreference", userPreference => new JArray(userPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Person person) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), person.ClassKind))); - jsonObject.Add("defaultDomain", this.PropertySerializerMap["defaultDomain"](person.DefaultDomain)); - jsonObject.Add("defaultEmailAddress", this.PropertySerializerMap["defaultEmailAddress"](person.DefaultEmailAddress)); - jsonObject.Add("defaultTelephoneNumber", this.PropertySerializerMap["defaultTelephoneNumber"](person.DefaultTelephoneNumber)); - jsonObject.Add("emailAddress", this.PropertySerializerMap["emailAddress"](person.EmailAddress.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](person.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](person.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("givenName", this.PropertySerializerMap["givenName"](person.GivenName)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](person.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](person.IsActive)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](person.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](person.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](person.Organization)); - jsonObject.Add("organizationalUnit", this.PropertySerializerMap["organizationalUnit"](person.OrganizationalUnit)); - jsonObject.Add("password", this.PropertySerializerMap["password"](person.Password)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](person.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](person.Role)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](person.ShortName)); - jsonObject.Add("surname", this.PropertySerializerMap["surname"](person.Surname)); - jsonObject.Add("telephoneNumber", this.PropertySerializerMap["telephoneNumber"](person.TelephoneNumber.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](person.ThingPreference)); - jsonObject.Add("userPreference", this.PropertySerializerMap["userPreference"](person.UserPreference.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultdomain": + var allowedVersionsForDefaultDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultDomain.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultemailaddress": + var allowedVersionsForDefaultEmailAddress = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultEmailAddress.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaulttelephonenumber": + var allowedVersionsForDefaultTelephoneNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultTelephoneNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "emailaddress": + var allowedVersionsForEmailAddress = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForEmailAddress.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("emailAddress"u8); + + if(value is IEnumerable objectListEmailAddress) + { + foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "givenname": + var allowedVersionsForGivenName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGivenName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("givenName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + var allowedVersionsForIsActive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsActive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + var allowedVersionsForOrganization = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganization.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalunit": + var allowedVersionsForOrganizationalUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganizationalUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organizationalUnit"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "password": + var allowedVersionsForPassword = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPassword.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("password"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + var allowedVersionsForRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRole.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "surname": + var allowedVersionsForSurname = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSurname.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("surname"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "telephonenumber": + var allowedVersionsForTelephoneNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTelephoneNumber.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("telephoneNumber"u8); + + if(value is IEnumerable objectListTelephoneNumber) + { + foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "userpreference": + var allowedVersionsForUserPreference = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUserPreference.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("userPreference"u8); + + if(value is IEnumerable objectListUserPreference) + { + foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Person person) + { + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); + return; } - var person = thing as Person; - if (person == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Person."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(person.Actor.HasValue) + { + writer.WriteStringValue(person.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(person); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index ee87b03ea..971c3903f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Point = CDP4Common.DTO.Point; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,439 @@ namespace CDP4JsonSerializer public class PointSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Point point) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), point.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](point.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](point.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](point.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](point.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](point.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](point.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](point.ThingPreference)); - jsonObject.Add("x", this.PropertySerializerMap["x"](point.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](point.Y)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + var allowedVersionsForX = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForX.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + var allowedVersionsForY = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForY.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Point"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); + return; } - var point = thing as Point; - if (point == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Point."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(point.Actor.HasValue) + { + writer.WriteStringValue(point.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(point); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index fefa85fcd..0d1cd3b88 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteStateList = CDP4Common.DTO.PossibleFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,820 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultState", defaultState => new JValue(defaultState) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "possibleState", possibleState => new JArray(((IEnumerable)possibleState).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteStateList possibleFiniteStateList) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteStateList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](possibleFiniteStateList.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteStateList.ClassKind))); - jsonObject.Add("defaultState", this.PropertySerializerMap["defaultState"](possibleFiniteStateList.DefaultState)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteStateList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteStateList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteStateList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteStateList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](possibleFiniteStateList.Owner)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](possibleFiniteStateList.PossibleState.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteStateList.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteStateList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteStateList.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultstate": + var allowedVersionsForDefaultState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultState.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + var allowedVersionsForPossibleState = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleState.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleState"u8); + + if(value is IEnumerable objectListPossibleState) + { + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteStateList"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); + return; } - var possibleFiniteStateList = thing as PossibleFiniteStateList; - if (possibleFiniteStateList == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a PossibleFiniteStateList."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(possibleFiniteStateList.Actor.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(possibleFiniteStateList); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index 232282589..8829ee1bb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteState = CDP4Common.DTO.PossibleFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,600 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteState possibleFiniteState) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteState.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteState.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteState.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteState.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteState.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteState.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteState.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteState.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteState.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteState.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteState"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not PossibleFiniteState possibleFiniteState) + { + throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); + return; } - var possibleFiniteState = thing as PossibleFiniteState; - if (possibleFiniteState == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a PossibleFiniteState."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(possibleFiniteState.Actor.HasValue) + { + writer.WriteStringValue(possibleFiniteState.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(possibleFiniteState); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index d1f86fc85..f6ed496f1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PrefixedUnit = CDP4Common.DTO.PrefixedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,634 @@ namespace CDP4JsonSerializer public class PrefixedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "prefix", prefix => new JValue(prefix) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PrefixedUnit prefixedUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](prefixedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), prefixedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](prefixedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](prefixedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](prefixedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](prefixedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](prefixedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](prefixedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](prefixedUnit.ModifiedOn)); - jsonObject.Add("prefix", this.PropertySerializerMap["prefix"](prefixedUnit.Prefix)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](prefixedUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](prefixedUnit.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](prefixedUnit.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "prefix": + var allowedVersionsForPrefix = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrefix.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("prefix"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + var allowedVersionsForReferenceUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PrefixedUnit"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not PrefixedUnit prefixedUnit) + { + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); + return; } - var prefixedUnit = thing as PrefixedUnit; - if (prefixedUnit == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a PrefixedUnit."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(prefixedUnit.Actor.HasValue) + { + writer.WriteStringValue(prefixedUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(prefixedUnit); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index 6c60f9637..69e006cea 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Publication = CDP4Common.DTO.Publication; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,508 @@ namespace CDP4JsonSerializer public class PublicationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "publishedParameter", publishedParameter => new JArray(publishedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Publication publication) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), publication.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](publication.CreatedOn)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](publication.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](publication.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](publication.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](publication.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](publication.ModifiedOn)); - jsonObject.Add("publishedParameter", this.PropertySerializerMap["publishedParameter"](publication.PublishedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](publication.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](publication.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + var allowedVersionsForDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedparameter": + var allowedVersionsForPublishedParameter = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublishedParameter.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("publishedParameter"u8); + + if(value is IEnumerable objectListPublishedParameter) + { + foreach(var publishedParameterItem in objectListPublishedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Publication"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); + return; } - var publication = thing as Publication; - if (publication == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Publication."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(publication.Actor.HasValue) + { + writer.WriteStringValue(publication.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(publication); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index cf157155e..0519f1a24 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using QuantityKindFactor = CDP4Common.DTO.QuantityKindFactor; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "quantityKind", quantityKind => new JValue(quantityKind) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(QuantityKindFactor quantityKindFactor) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), quantityKindFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](quantityKindFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](quantityKindFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](quantityKindFactor.ModifiedOn)); - jsonObject.Add("quantityKind", this.PropertySerializerMap["quantityKind"](quantityKindFactor.QuantityKind)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](quantityKindFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](quantityKindFactor.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + var allowedVersionsForExponent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExponent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykind": + var allowedVersionsForQuantityKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForQuantityKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the QuantityKindFactor"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not QuantityKindFactor quantityKindFactor) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); } - var quantityKindFactor = thing as QuantityKindFactor; - if (quantityKindFactor == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a QuantityKindFactor."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(quantityKindFactor.Actor.HasValue) + { + writer.WriteStringValue(quantityKindFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(quantityKindFactor); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index 794779e10..4ad6a83b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RatioScale = CDP4Common.DTO.RatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -44,97 +50,1022 @@ namespace CDP4JsonSerializer public class RatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RatioScale ratioScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ratioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ratioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ratioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ratioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ratioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ratioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ratioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ratioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ratioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ratioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ratioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ratioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ratioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ratioScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ratioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ratioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ratioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ratioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ratioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ratioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ratioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ratioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ratioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + var allowedVersionsForIsMaximumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + var allowedVersionsForIsMinimumInclusive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + var allowedVersionsForMappingToReferenceScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + var allowedVersionsForMaximumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + var allowedVersionsForMinimumPermissibleValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + var allowedVersionsForNegativeValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + var allowedVersionsForNumberSet = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + var allowedVersionsForPositiveValueConnotation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + var allowedVersionsForValueDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RatioScale ratioScale) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); } - var ratioScale = thing as RatioScale; - if (ratioScale == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a RatioScale."); + Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ratioScale.Actor.HasValue) + { + writer.WriteStringValue(ratioScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(ratioScale); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index 5fc66c14f..d86691242 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferenceSource = CDP4Common.DTO.ReferenceSource; /// /// The purpose of the class is to provide a specific serializer @@ -44,93 +50,1074 @@ namespace CDP4JsonSerializer public class ReferenceSourceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "language", language => new JValue(language) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "publicationYear", publicationYear => new JValue(publicationYear) }, - { "publishedIn", publishedIn => new JValue(publishedIn) }, - { "publisher", publisher => new JValue(publisher) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "versionDate", versionDate => new JValue(versionDate != null ? ((DateTime)versionDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "versionIdentifier", versionIdentifier => new JValue(versionIdentifier) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReferenceSource referenceSource) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referenceSource.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](referenceSource.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](referenceSource.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referenceSource.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referenceSource.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referenceSource.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referenceSource.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referenceSource.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referenceSource.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referenceSource.IsDeprecated)); - jsonObject.Add("language", this.PropertySerializerMap["language"](referenceSource.Language)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referenceSource.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referenceSource.Name)); - jsonObject.Add("publicationYear", this.PropertySerializerMap["publicationYear"](referenceSource.PublicationYear)); - jsonObject.Add("publishedIn", this.PropertySerializerMap["publishedIn"](referenceSource.PublishedIn)); - jsonObject.Add("publisher", this.PropertySerializerMap["publisher"](referenceSource.Publisher)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referenceSource.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referenceSource.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referenceSource.ThingPreference)); - jsonObject.Add("versionDate", this.PropertySerializerMap["versionDate"](referenceSource.VersionDate)); - jsonObject.Add("versionIdentifier", this.PropertySerializerMap["versionIdentifier"](referenceSource.VersionIdentifier)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "language": + var allowedVersionsForLanguage = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguage.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("language"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publicationyear": + var allowedVersionsForPublicationYear = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublicationYear.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publicationYear"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedin": + var allowedVersionsForPublishedIn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublishedIn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publishedIn"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publisher": + var allowedVersionsForPublisher = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPublisher.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publisher"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versiondate": + var allowedVersionsForVersionDate = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForVersionDate.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("versionDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versionidentifier": + var allowedVersionsForVersionIdentifier = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForVersionIdentifier.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("versionIdentifier"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferenceSource"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ReferenceSource referenceSource) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); } - var referenceSource = thing as ReferenceSource; - if (referenceSource == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ReferenceSource."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referenceSource.Actor.HasValue) + { + writer.WriteStringValue(referenceSource.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(referenceSource); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index 5003f32fe..48553ff25 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferencerRule = CDP4Common.DTO.ReferencerRule; /// /// The purpose of the class is to provide a specific serializer @@ -44,85 +50,794 @@ namespace CDP4JsonSerializer public class ReferencerRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxReferenced", maxReferenced => new JValue(maxReferenced) }, - { "minReferenced", minReferenced => new JValue(minReferenced) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referencedCategory", referencedCategory => new JArray(referencedCategory) }, - { "referencingCategory", referencingCategory => new JValue(referencingCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReferencerRule referencerRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referencerRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referencerRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referencerRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referencerRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referencerRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referencerRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referencerRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referencerRule.IsDeprecated)); - jsonObject.Add("maxReferenced", this.PropertySerializerMap["maxReferenced"](referencerRule.MaxReferenced)); - jsonObject.Add("minReferenced", this.PropertySerializerMap["minReferenced"](referencerRule.MinReferenced)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referencerRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referencerRule.Name)); - jsonObject.Add("referencedCategory", this.PropertySerializerMap["referencedCategory"](referencerRule.ReferencedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencingCategory", this.PropertySerializerMap["referencingCategory"](referencerRule.ReferencingCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referencerRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referencerRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referencerRule.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxreferenced": + var allowedVersionsForMaxReferenced = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMaxReferenced.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minreferenced": + var allowedVersionsForMinReferenced = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForMinReferenced.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedcategory": + var allowedVersionsForReferencedCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referencedCategory"u8); + + if(value is IEnumerable objectListReferencedCategory) + { + foreach(var referencedCategoryItem in objectListReferencedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "referencingcategory": + var allowedVersionsForReferencingCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencingCategory.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferencerRule"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); + return; } - var referencerRule = thing as ReferencerRule; - if (referencerRule == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ReferencerRule."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referencerRule.Actor.HasValue) + { + writer.WriteStringValue(referencerRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(referencerRule); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index d16185572..c7a9b5bf9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationalExpression = CDP4Common.DTO.RelationalExpression; /// /// The purpose of the class is to provide a specific serializer @@ -44,73 +50,516 @@ namespace CDP4JsonSerializer public class RelationalExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "relationalOperator", relationalOperator => new JValue(relationalOperator.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RelationalExpression relationalExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationalExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationalExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationalExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationalExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationalExpression.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationalExpression.ParameterType)); - jsonObject.Add("relationalOperator", this.PropertySerializerMap["relationalOperator"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RelationalOperatorKind), relationalExpression.RelationalOperator))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationalExpression.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationalExpression.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationalExpression.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationalExpression.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationaloperator": + var allowedVersionsForRelationalOperator = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelationalOperator.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationalOperator"u8); + + if(value != null) + { + writer.WriteStringValue(((RelationalOperatorKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationalExpression"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RelationalExpression relationalExpression) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); } - var relationalExpression = thing as RelationalExpression; - if (relationalExpression == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a RelationalExpression."); + Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationalExpression.Actor.HasValue) + { + writer.WriteStringValue(relationalExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(relationalExpression); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 970207037..a7653761d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationshipParameterValue = CDP4Common.DTO.RelationshipParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,453 @@ namespace CDP4JsonSerializer public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RelationshipParameterValue relationshipParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationshipParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationshipParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationshipParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationshipParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationshipParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationshipParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationshipParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationshipParameterValue.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationshipParameterValue"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RelationshipParameterValue relationshipParameterValue) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); } - var relationshipParameterValue = thing as RelationshipParameterValue; - if (relationshipParameterValue == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a RelationshipParameterValue."); + Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationshipParameterValue.Actor.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(relationshipParameterValue); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 5126401cf..c9ae82ee9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForDeviation = CDP4Common.DTO.RequestForDeviation; /// /// The purpose of the class is to provide a specific serializer @@ -44,95 +50,928 @@ namespace CDP4JsonSerializer public class RequestForDeviationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequestForDeviation requestForDeviation) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForDeviation.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForDeviation.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForDeviation.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForDeviation.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForDeviation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForDeviation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForDeviation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForDeviation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForDeviation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForDeviation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForDeviation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForDeviation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForDeviation.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForDeviation.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForDeviation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForDeviation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForDeviation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForDeviation.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForDeviation.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForDeviation.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForDeviation.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForDeviation.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForDeviation"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); + return; } - var requestForDeviation = thing as RequestForDeviation; - if (requestForDeviation == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a RequestForDeviation."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForDeviation.Actor.HasValue) + { + writer.WriteStringValue(requestForDeviation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requestForDeviation); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index fab849eb3..322fed874 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForWaiver = CDP4Common.DTO.RequestForWaiver; /// /// The purpose of the class is to provide a specific serializer @@ -44,95 +50,928 @@ namespace CDP4JsonSerializer public class RequestForWaiverSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequestForWaiver requestForWaiver) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForWaiver.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForWaiver.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForWaiver.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForWaiver.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForWaiver.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForWaiver.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForWaiver.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForWaiver.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForWaiver.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForWaiver.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForWaiver.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForWaiver.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForWaiver.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForWaiver.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForWaiver.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForWaiver.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForWaiver.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForWaiver.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForWaiver.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForWaiver.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForWaiver.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForWaiver.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForWaiver"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); + return; } - var requestForWaiver = thing as RequestForWaiver; - if (requestForWaiver == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a RequestForWaiver."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForWaiver.Actor.HasValue) + { + writer.WriteStringValue(requestForWaiver.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requestForWaiver); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 60b3a6930..489a7dab0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Requirement = CDP4Common.DTO.Requirement; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,912 @@ namespace CDP4JsonSerializer public class RequirementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JValue(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "parametricConstraint", parametricConstraint => new JArray(((IEnumerable)parametricConstraint).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Requirement requirement) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirement.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirement.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirement.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirement.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirement.Group)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirement.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirement.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirement.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirement.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirement.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirement.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirement.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parametricConstraint", this.PropertySerializerMap["parametricConstraint"](requirement.ParametricConstraint.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirement.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirement.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirement.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + var allowedVersionsForGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGroup.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + var allowedVersionsForParameterValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "parametricconstraint": + var allowedVersionsForParametricConstraint = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParametricConstraint.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parametricConstraint"u8); + + if(value is IEnumerable objectListParametricConstraint) + { + foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Requirement"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Requirement requirement) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); } - var requirement = thing as Requirement; - if (requirement == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Requirement."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirement.Actor.HasValue) + { + writer.WriteStringValue(requirement.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requirement); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 8d139c938..21e384c1f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsContainerParameterValue = CDP4Common.DTO.RequirementsContainerParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,453 @@ namespace CDP4JsonSerializer public class RequirementsContainerParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsContainerParameterValue requirementsContainerParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsContainerParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsContainerParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsContainerParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](requirementsContainerParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsContainerParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](requirementsContainerParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsContainerParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](requirementsContainerParameterValue.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsContainerParameterValue"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); } - var requirementsContainerParameterValue = thing as RequirementsContainerParameterValue; - if (requirementsContainerParameterValue == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a RequirementsContainerParameterValue."); + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsContainerParameterValue.Actor.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requirementsContainerParameterValue); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 3cd2879a4..496d84ec6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsGroup = CDP4Common.DTO.RequirementsGroup; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,790 @@ namespace CDP4JsonSerializer public class RequirementsGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsGroup requirementsGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsGroup.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsGroup.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsGroup.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsGroup.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsGroup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + var allowedVersionsForGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("group"u8); + + if(value is IEnumerable objectListGroup) + { + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + var allowedVersionsForParameterValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsGroup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); + return; } - var requirementsGroup = thing as RequirementsGroup; - if (requirementsGroup == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a RequirementsGroup."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsGroup.Actor.HasValue) + { + writer.WriteStringValue(requirementsGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requirementsGroup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index f8022c191..3f9c5533f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsSpecification = CDP4Common.DTO.RequirementsSpecification; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,882 @@ namespace CDP4JsonSerializer public class RequirementsSpecificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsSpecification requirementsSpecification) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsSpecification.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsSpecification.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsSpecification.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsSpecification.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsSpecification.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsSpecification.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsSpecification.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirementsSpecification.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsSpecification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsSpecification.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsSpecification.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsSpecification.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](requirementsSpecification.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsSpecification.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsSpecification.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsSpecification.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + var allowedVersionsForGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("group"u8); + + if(value is IEnumerable objectListGroup) + { + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + var allowedVersionsForParameterValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "requirement": + var allowedVersionsForRequirement = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequirement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirement"u8); + + if(value is IEnumerable objectListRequirement) + { + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsSpecification"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); + return; } - var requirementsSpecification = thing as RequirementsSpecification; - if (requirementsSpecification == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a RequirementsSpecification."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsSpecification.Actor.HasValue) + { + writer.WriteStringValue(requirementsSpecification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(requirementsSpecification); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index 761318705..ae3bf64b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReviewItemDiscrepancy = CDP4Common.DTO.ReviewItemDiscrepancy; /// /// The purpose of the class is to provide a specific serializer @@ -44,97 +50,977 @@ namespace CDP4JsonSerializer public class ReviewItemDiscrepancySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "solution", solution => new JArray(solution) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReviewItemDiscrepancy reviewItemDiscrepancy) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](reviewItemDiscrepancy.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](reviewItemDiscrepancy.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), reviewItemDiscrepancy.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), reviewItemDiscrepancy.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](reviewItemDiscrepancy.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](reviewItemDiscrepancy.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](reviewItemDiscrepancy.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](reviewItemDiscrepancy.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](reviewItemDiscrepancy.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](reviewItemDiscrepancy.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](reviewItemDiscrepancy.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](reviewItemDiscrepancy.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](reviewItemDiscrepancy.ShortName)); - jsonObject.Add("solution", this.PropertySerializerMap["solution"](reviewItemDiscrepancy.Solution)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), reviewItemDiscrepancy.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](reviewItemDiscrepancy.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](reviewItemDiscrepancy.Title)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + var allowedVersionsForApprovedBy = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + var allowedVersionsForClassification = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassification.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "solution": + var allowedVersionsForSolution = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSolution.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("solution"u8); + + if(value is IEnumerable objectListSolution) + { + foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + } + + writer.WriteEndArray(); + break; + case "sourceannotation": + var allowedVersionsForSourceAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + var allowedVersionsForTitle = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForTitle.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReviewItemDiscrepancy"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); } - var reviewItemDiscrepancy = thing as ReviewItemDiscrepancy; - if (reviewItemDiscrepancy == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ReviewItemDiscrepancy."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(reviewItemDiscrepancy.Actor.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(reviewItemDiscrepancy); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index ce2c6cb9e..4da2b357e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleVerificationList = CDP4Common.DTO.RuleVerificationList; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,692 @@ namespace CDP4JsonSerializer public class RuleVerificationListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerification", ruleVerification => new JArray(((IEnumerable)ruleVerification).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RuleVerificationList ruleVerificationList) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ruleVerificationList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleVerificationList.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ruleVerificationList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ruleVerificationList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleVerificationList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleVerificationList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ruleVerificationList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](ruleVerificationList.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleVerificationList.RevisionNumber)); - jsonObject.Add("ruleVerification", this.PropertySerializerMap["ruleVerification"](ruleVerificationList.RuleVerification.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ruleVerificationList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleVerificationList.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverification": + var allowedVersionsForRuleVerification = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRuleVerification.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("ruleVerification"u8); + + if(value is IEnumerable objectListRuleVerification) + { + foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleVerificationList"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RuleVerificationList ruleVerificationList) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); } - var ruleVerificationList = thing as RuleVerificationList; - if (ruleVerificationList == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a RuleVerificationList."); + Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleVerificationList.Actor.HasValue) + { + writer.WriteStringValue(ruleVerificationList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(ruleVerificationList); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index 839fe1599..e7f25e745 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleViolation = CDP4Common.DTO.RuleViolation; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,450 @@ namespace CDP4JsonSerializer public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violatingThing", violatingThing => new JArray(violatingThing) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RuleViolation ruleViolation) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleViolation.ClassKind))); - jsonObject.Add("description", this.PropertySerializerMap["description"](ruleViolation.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleViolation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleViolation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleViolation.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleViolation.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleViolation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleViolation.ThingPreference)); - jsonObject.Add("violatingThing", this.PropertySerializerMap["violatingThing"](ruleViolation.ViolatingThing.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + var allowedVersionsForDescription = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDescription.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violatingthing": + var allowedVersionsForViolatingThing = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForViolatingThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violatingThing"u8); + + if(value is IEnumerable objectListViolatingThing) + { + foreach(var violatingThingItem in objectListViolatingThing) + { + writer.WriteStringValue((Guid)violatingThingItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleViolation"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); + return; } - var ruleViolation = thing as RuleViolation; - if (ruleViolation == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a RuleViolation."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleViolation.Actor.HasValue) + { + writer.WriteStringValue(ruleViolation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(ruleViolation); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index f0483dd49..1ba4dc61f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SampledFunctionParameterType = CDP4Common.DTO.SampledFunctionParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,89 +50,730 @@ namespace CDP4JsonSerializer public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "degreeOfInterpolation", degreeOfInterpolation => new JValue(degreeOfInterpolation) }, - { "dependentParameterType", dependentParameterType => new JArray(((IEnumerable)dependentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "independentParameterType", independentParameterType => new JArray(((IEnumerable)independentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "interpolationPeriod", interpolationPeriod => new JValue(((ValueArray)interpolationPeriod).ToJsonString()) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SampledFunctionParameterType sampledFunctionParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](sampledFunctionParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](sampledFunctionParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sampledFunctionParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](sampledFunctionParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("degreeOfInterpolation", this.PropertySerializerMap["degreeOfInterpolation"](sampledFunctionParameterType.DegreeOfInterpolation)); - jsonObject.Add("dependentParameterType", this.PropertySerializerMap["dependentParameterType"](sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sampledFunctionParameterType.Iid)); - jsonObject.Add("independentParameterType", this.PropertySerializerMap["independentParameterType"](sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("interpolationPeriod", this.PropertySerializerMap["interpolationPeriod"](sampledFunctionParameterType.InterpolationPeriod)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](sampledFunctionParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sampledFunctionParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sampledFunctionParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sampledFunctionParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](sampledFunctionParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](sampledFunctionParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sampledFunctionParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "degreeofinterpolation": + var allowedVersionsForDegreeOfInterpolation = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDegreeOfInterpolation.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "dependentparametertype": + var allowedVersionsForDependentParameterType = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDependentParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("dependentParameterType"u8); + + if(value is IEnumerable objectListDependentParameterType) + { + foreach(var dependentParameterTypeItem in objectListDependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "independentparametertype": + var allowedVersionsForIndependentParameterType = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIndependentParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("independentParameterType"u8); + + if(value is IEnumerable objectListIndependentParameterType) + { + foreach(var independentParameterTypeItem in objectListIndependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "interpolationperiod": + var allowedVersionsForInterpolationPeriod = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForInterpolationPeriod.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("interpolationPeriod"u8, ((ValueArray)value).ToJsonString()); + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SampledFunctionParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); + return; } - var sampledFunctionParameterType = thing as SampledFunctionParameterType; - if (sampledFunctionParameterType == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SampledFunctionParameterType."); + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SampledFunctionParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SampledFunctionParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sampledFunctionParameterType.Actor.HasValue) + { + writer.WriteStringValue(sampledFunctionParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(sampledFunctionParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index c775a39a0..e65485253 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleReferenceQuantityValue = CDP4Common.DTO.ScaleReferenceQuantityValue; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ScaleReferenceQuantityValue scaleReferenceQuantityValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleReferenceQuantityValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleReferenceQuantityValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleReferenceQuantityValue.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleReferenceQuantityValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](scaleReferenceQuantityValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleReferenceQuantityValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleReferenceQuantityValue.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleReferenceQuantityValue"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); } - var scaleReferenceQuantityValue = thing as ScaleReferenceQuantityValue; - if (scaleReferenceQuantityValue == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ScaleReferenceQuantityValue."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleReferenceQuantityValue.Actor.HasValue) + { + writer.WriteStringValue(scaleReferenceQuantityValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(scaleReferenceQuantityValue); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index 54efd1fa7..492f146e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleValueDefinition = CDP4Common.DTO.ScaleValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,634 @@ namespace CDP4JsonSerializer public class ScaleValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ScaleValueDefinition scaleValueDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](scaleValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](scaleValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](scaleValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](scaleValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](scaleValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleValueDefinition.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleValueDefinition.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleValueDefinition"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ScaleValueDefinition scaleValueDefinition) + { + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); + return; } - var scaleValueDefinition = thing as ScaleValueDefinition; - if (scaleValueDefinition == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ScaleValueDefinition."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleValueDefinition.Actor.HasValue) + { + writer.WriteStringValue(scaleValueDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(scaleValueDefinition); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index b915c1d23..49fb9fa52 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Section = CDP4Common.DTO.Section; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,568 @@ namespace CDP4JsonSerializer public class SectionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "page", page => new JArray(((IEnumerable)page).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Section section) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](section.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), section.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](section.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](section.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](section.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](section.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](section.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](section.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](section.Owner)); - jsonObject.Add("page", this.PropertySerializerMap["page"](section.Page.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](section.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](section.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](section.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "page": + var allowedVersionsForPage = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPage.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("page"u8); + + if(value is IEnumerable objectListPage) + { + foreach(var pageItem in objectListPage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Section"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Section section) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Section", nameof(thing)); } - var section = thing as Section; - if (section == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a Section."); + Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(section.Actor.HasValue) + { + writer.WriteStringValue(section.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(section); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs index 723578ffb..e638d2d62 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2023 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +30,13 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - + using System.Text.Json; + using CDP4Common; using CDP4Common.DTO; - + using CDP4JsonSerializer.Helper; - using Newtonsoft.Json.Linq; - /// /// A static class that provides method to serialize a or a /// @@ -46,7 +45,7 @@ public static class SerializerProvider /// /// The map containing the Serializers /// - private static readonly Dictionary SerializerMap = new Dictionary + private static readonly Dictionary SerializerMap = new() { { "ActionItem", new ActionItemSerializer() }, { "ActualFiniteState", new ActualFiniteStateSerializer() }, @@ -197,42 +196,43 @@ public static class SerializerProvider }; /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this Thing thing) + /// The + /// The that has been requested for the serialization + public static void SerializeThing(this Thing thing, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out serializer)) + if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out var serializer)) { throw new NotSupportedException($"The {thing.ClassKind} class is not registered"); } - - return serializer.Serialize(thing); + + serializer.Serialize(thing, writer, requestedVersion); } - + /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this ClasslessDTO classlessDto) + /// The + /// The that has been requested for the serialization + public static void SerializeClasslessDto(this ClasslessDTO classlessDto, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out serializer)) + if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out var serializer)) { throw new NotSupportedException($"The {classlessDto["ClassKind"]} class is not registered"); } - var jsonObject = new JObject(); + writer.WriteStartObject(); + foreach (var keyValue in classlessDto) { var key = Utils.LowercaseFirstLetter(keyValue.Key); - jsonObject.Add(key, serializer.PropertySerializerMap[key](keyValue.Value)); + serializer.SerializeProperty(key, keyValue.Value, writer, requestedVersion); } - return jsonObject; + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index f11e71715..c5318bfc6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SharedStyle = CDP4Common.DTO.SharedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -44,93 +50,1095 @@ namespace CDP4JsonSerializer public class SharedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SharedStyle sharedStyle) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sharedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sharedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sharedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](sharedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](sharedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](sharedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](sharedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](sharedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](sharedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](sharedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](sharedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](sharedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sharedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sharedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sharedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sharedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](sharedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](sharedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](sharedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sharedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](sharedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + var allowedVersionsForFillColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFillColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + var allowedVersionsForFillOpacity = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFillOpacity.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontbold": + var allowedVersionsForFontBold = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontBold.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + var allowedVersionsForFontColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontitalic": + var allowedVersionsForFontItalic = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontItalic.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + var allowedVersionsForFontName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + var allowedVersionsForFontSize = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontSize.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + var allowedVersionsForFontStrokeThrough = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontStrokeThrough.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + var allowedVersionsForFontUnderline = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFontUnderline.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + var allowedVersionsForStrokeColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeColor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + var allowedVersionsForStrokeOpacity = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeOpacity.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + var allowedVersionsForStrokeWidth = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStrokeWidth.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + var allowedVersionsForUsedColor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUsedColor.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("usedColor"u8); + + if(value is IEnumerable objectListUsedColor) + { + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SharedStyle sharedStyle) + { + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); + return; } - var sharedStyle = thing as SharedStyle; - if (sharedStyle == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SharedStyle."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sharedStyle.Actor.HasValue) + { + writer.WriteStringValue(sharedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(sharedStyle); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 4b70f6b93..f8aae430a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleParameterValue = CDP4Common.DTO.SimpleParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,482 @@ namespace CDP4JsonSerializer public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleParameterValue simpleParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](simpleParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](simpleParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](simpleParameterValue.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleParameterValue"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SimpleParameterValue simpleParameterValue) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); } - var simpleParameterValue = thing as SimpleParameterValue; - if (simpleParameterValue == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a SimpleParameterValue."); + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleParameterValue.Actor.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(simpleParameterValue); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index fac2f56b2..d1564944c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleQuantityKind = CDP4Common.DTO.SimpleQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,852 @@ namespace CDP4JsonSerializer public class SimpleQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleQuantityKind simpleQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](simpleQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](simpleQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](simpleQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](simpleQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](simpleQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleQuantityKind.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + var allowedVersionsForDefaultScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + var allowedVersionsForPossibleScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + var allowedVersionsForQuantityDimensionSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleQuantityKind"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SimpleQuantityKind simpleQuantityKind) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); } - var simpleQuantityKind = thing as SimpleQuantityKind; - if (simpleQuantityKind == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SimpleQuantityKind."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(simpleQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(simpleQuantityKind); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 4cf8ffb62..37ce4c2b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleUnit = CDP4Common.DTO.SimpleUnit; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,634 @@ namespace CDP4JsonSerializer public class SimpleUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleUnit simpleUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleUnit.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleUnit"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SimpleUnit simpleUnit) + { + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); + return; } - var simpleUnit = thing as SimpleUnit; - if (simpleUnit == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SimpleUnit."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleUnit.Actor.HasValue) + { + writer.WriteStringValue(simpleUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(simpleUnit); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 92fdee2df..91fb72ddb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataAnnotation = CDP4Common.DTO.SiteDirectoryDataAnnotation; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,599 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataAnnotation.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataAnnotation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataAnnotation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataAnnotation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataAnnotation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataAnnotation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataAnnotation.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](siteDirectoryDataAnnotation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataAnnotation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataAnnotation.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + var allowedVersionsForDiscussion = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + var allowedVersionsForPrimaryAnnotatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + var allowedVersionsForRelatedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataAnnotation"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); } - var siteDirectoryDataAnnotation = thing as SiteDirectoryDataAnnotation; - if (siteDirectoryDataAnnotation == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataAnnotation."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataAnnotation.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataAnnotation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteDirectoryDataAnnotation); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index 2f12b765d..b04f9b5d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataDiscussionItem = CDP4Common.DTO.SiteDirectoryDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,528 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](siteDirectoryDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataDiscussionItem.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + var allowedVersionsForReplyTo = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReplyTo.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataDiscussionItem"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); } - var siteDirectoryDataDiscussionItem = thing as SiteDirectoryDataDiscussionItem; - if (siteDirectoryDataDiscussionItem == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataDiscussionItem."); + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteDirectoryDataDiscussionItem); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index f29372de4..0b02b53b6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectory = CDP4Common.DTO.SiteDirectory; /// /// The purpose of the class is to provide a specific serializer @@ -44,99 +50,1263 @@ namespace CDP4JsonSerializer public class SiteDirectorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "annotation", annotation => new JArray(annotation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "defaultParticipantRole", defaultParticipantRole => new JValue(defaultParticipantRole) }, - { "defaultPersonRole", defaultPersonRole => new JValue(defaultPersonRole) }, - { "domain", domain => new JArray(domain) }, - { "domainGroup", domainGroup => new JArray(domainGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "model", model => new JArray(model) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "naturalLanguage", naturalLanguage => new JArray(naturalLanguage) }, - { "organization", organization => new JArray(organization) }, - { "participantRole", participantRole => new JArray(participantRole) }, - { "person", person => new JArray(person) }, - { "personRole", personRole => new JArray(personRole) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "siteReferenceDataLibrary", siteReferenceDataLibrary => new JArray(siteReferenceDataLibrary) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectory siteDirectory) - { - var jsonObject = new JObject(); - jsonObject.Add("annotation", this.PropertySerializerMap["annotation"](siteDirectory.Annotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectory.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectory.CreatedOn)); - jsonObject.Add("defaultParticipantRole", this.PropertySerializerMap["defaultParticipantRole"](siteDirectory.DefaultParticipantRole)); - jsonObject.Add("defaultPersonRole", this.PropertySerializerMap["defaultPersonRole"](siteDirectory.DefaultPersonRole)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](siteDirectory.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainGroup", this.PropertySerializerMap["domainGroup"](siteDirectory.DomainGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectory.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectory.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectory.Iid)); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](siteDirectory.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](siteDirectory.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("model", this.PropertySerializerMap["model"](siteDirectory.Model.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectory.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteDirectory.Name)); - jsonObject.Add("naturalLanguage", this.PropertySerializerMap["naturalLanguage"](siteDirectory.NaturalLanguage.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](siteDirectory.Organization.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participantRole", this.PropertySerializerMap["participantRole"](siteDirectory.ParticipantRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("person", this.PropertySerializerMap["person"](siteDirectory.Person.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("personRole", this.PropertySerializerMap["personRole"](siteDirectory.PersonRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectory.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteDirectory.ShortName)); - jsonObject.Add("siteReferenceDataLibrary", this.PropertySerializerMap["siteReferenceDataLibrary"](siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectory.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "annotation": + var allowedVersionsForAnnotation = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAnnotation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("annotation"u8); + + if(value is IEnumerable objectListAnnotation) + { + foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultparticipantrole": + var allowedVersionsForDefaultParticipantRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultParticipantRole.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultParticipantRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultpersonrole": + var allowedVersionsForDefaultPersonRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultPersonRole.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + var allowedVersionsForDomain = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "domaingroup": + var allowedVersionsForDomainGroup = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDomainGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domainGroup"u8); + + if(value is IEnumerable objectListDomainGroup) + { + foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lastmodifiedon": + var allowedVersionsForLastModifiedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLastModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + var allowedVersionsForLogEntry = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLogEntry.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntry"u8); + + if(value is IEnumerable objectListLogEntry) + { + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + } + + writer.WriteEndArray(); + break; + case "model": + var allowedVersionsForModel = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModel.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("model"u8); + + if(value is IEnumerable objectListModel) + { + foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "naturallanguage": + var allowedVersionsForNaturalLanguage = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForNaturalLanguage.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("naturalLanguage"u8); + + if(value is IEnumerable objectListNaturalLanguage) + { + foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + } + + writer.WriteEndArray(); + break; + case "organization": + var allowedVersionsForOrganization = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOrganization.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organization"u8); + + if(value is IEnumerable objectListOrganization) + { + foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + } + + writer.WriteEndArray(); + break; + case "participantrole": + var allowedVersionsForParticipantRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParticipantRole.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participantRole"u8); + + if(value is IEnumerable objectListParticipantRole) + { + foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + } + + writer.WriteEndArray(); + break; + case "person": + var allowedVersionsForPerson = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("person"u8); + + if(value is IEnumerable objectListPerson) + { + foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + } + + writer.WriteEndArray(); + break; + case "personrole": + var allowedVersionsForPersonRole = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPersonRole.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("personRole"u8); + + if(value is IEnumerable objectListPersonRole) + { + foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sitereferencedatalibrary": + var allowedVersionsForSiteReferenceDataLibrary = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSiteReferenceDataLibrary.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + if(value is IEnumerable objectListSiteReferenceDataLibrary) + { + foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectory"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteDirectory siteDirectory) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); } - var siteDirectory = thing as SiteDirectory; - if (siteDirectory == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a SiteDirectory."); + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.1.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.2.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectory.Actor.HasValue) + { + writer.WriteStringValue(siteDirectory.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteDirectory); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 2b33b4e6b..22b0c2310 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryThingReference = CDP4Common.DTO.SiteDirectoryThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,408 @@ namespace CDP4JsonSerializer public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryThingReference siteDirectoryThingReference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](siteDirectoryThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](siteDirectoryThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryThingReference.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedrevisionnumber": + var allowedVersionsForReferencedRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + var allowedVersionsForReferencedThing = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferencedThing.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryThingReference"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); } - var siteDirectoryThingReference = thing as SiteDirectoryThingReference; - if (siteDirectoryThingReference == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SiteDirectoryThingReference."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryThingReference.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteDirectoryThingReference); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index b5912bc0b..89790245c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteLogEntry = CDP4Common.DTO.SiteLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -44,83 +50,778 @@ namespace CDP4JsonSerializer public class SiteLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteLogEntry siteLogEntry) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](siteLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](siteLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](siteLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), siteLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteLogEntry.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteddomainiid": + var allowedVersionsForAffectedDomainIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedDomainIid.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) + { + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + } + + writer.WriteEndArray(); + break; + case "affecteditemiid": + var allowedVersionsForAffectedItemIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedItemIid"u8); + + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + var allowedVersionsForLevel = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLevel.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + var allowedVersionsForLogEntryChangelogItem = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLogEntryChangelogItem.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntryChangelogItem"u8); + + if(value is IEnumerable objectListLogEntryChangelogItem) + { + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteLogEntry"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); + return; } - var siteLogEntry = thing as SiteLogEntry; - if (siteLogEntry == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SiteLogEntry."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteLogEntry.Actor.HasValue) + { + writer.WriteStringValue(siteLogEntry.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteLogEntry); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index ce4c3fe0d..138ecdcfc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteReferenceDataLibrary = CDP4Common.DTO.SiteReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -44,103 +50,1400 @@ namespace CDP4JsonSerializer public class SiteReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteReferenceDataLibrary siteReferenceDataLibrary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](siteReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](siteReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](siteReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](siteReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteReferenceDataLibrary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](siteReferenceDataLibrary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](siteReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](siteReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](siteReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](siteReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "basequantitykind": + var allowedVersionsForBaseQuantityKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBaseQuantityKind.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseQuantityKind"u8); + + if(value is IEnumerable objectListBaseQuantityKind) + { + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + } + + writer.WriteEndArray(); + break; + case "baseunit": + var allowedVersionsForBaseUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForBaseUnit.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseUnit"u8); + + if(value is IEnumerable objectListBaseUnit) + { + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + var allowedVersionsForConstant = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForConstant.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + + writer.WriteEndArray(); + break; + case "definedcategory": + var allowedVersionsForDefinedCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinedCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definedCategory"u8); + + if(value is IEnumerable objectListDefinedCategory) + { + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + var allowedVersionsForFileType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForFileType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "glossary": + var allowedVersionsForGlossary = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGlossary.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("glossary"u8); + + if(value is IEnumerable objectListGlossary) + { + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + var allowedVersionsForParameterType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForParameterType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "referencesource": + var allowedVersionsForReferenceSource = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForReferenceSource.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceSource"u8); + + if(value is IEnumerable objectListReferenceSource) + { + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + var allowedVersionsForRequiredRdl = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + var allowedVersionsForRule = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRule.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("rule"u8); + + if(value is IEnumerable objectListRule) + { + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + } + + writer.WriteEndArray(); + break; + case "scale": + var allowedVersionsForScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("scale"u8); + + if(value is IEnumerable objectListScale) + { + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unit"u8); + + if(value is IEnumerable objectListUnit) + { + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + } + + writer.WriteEndArray(); + break; + case "unitprefix": + var allowedVersionsForUnitPrefix = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnitPrefix.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitPrefix"u8); + + if(value is IEnumerable objectListUnitPrefix) + { + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); + return; } - var siteReferenceDataLibrary = thing as SiteReferenceDataLibrary; - if (siteReferenceDataLibrary == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SiteReferenceDataLibrary."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(siteReferenceDataLibrary); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 68a30823e..96fb334f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Solution = CDP4Common.DTO.Solution; /// /// The purpose of the class is to provide a specific serializer @@ -44,75 +50,501 @@ namespace CDP4JsonSerializer public class SolutionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Solution solution) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](solution.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), solution.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](solution.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](solution.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](solution.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](solution.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](solution.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](solution.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](solution.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](solution.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](solution.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](solution.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + var allowedVersionsForAuthor = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAuthor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Solution"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Solution solution) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); } - var solution = thing as Solution; - if (solution == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a Solution."); + Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(solution.Actor.HasValue) + { + writer.WriteStringValue(solution.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(solution); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index 3e49c04b2..411b0211e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SpecializedQuantityKind = CDP4Common.DTO.SpecializedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -44,89 +50,886 @@ namespace CDP4JsonSerializer public class SpecializedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "general", general => new JValue(general) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SpecializedQuantityKind specializedQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](specializedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](specializedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), specializedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](specializedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](specializedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("general", this.PropertySerializerMap["general"](specializedQuantityKind.General)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](specializedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](specializedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](specializedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](specializedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](specializedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](specializedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](specializedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](specializedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](specializedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](specializedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](specializedQuantityKind.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + var allowedVersionsForDefaultScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "general": + var allowedVersionsForGeneral = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGeneral.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("general"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + var allowedVersionsForPossibleScale = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + var allowedVersionsForQuantityDimensionSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SpecializedQuantityKind"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); + return; } - var specializedQuantityKind = thing as SpecializedQuantityKind; - if (specializedQuantityKind == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a SpecializedQuantityKind."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(specializedQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(specializedQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(specializedQuantityKind); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index e03e6baab..336a62045 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMap = CDP4Common.DTO.StakeHolderValueMap; /// /// The purpose of the class is to provide a specific serializer @@ -44,87 +50,849 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goal", goal => new JArray(goal) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "settings", settings => new JArray(settings) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMap stakeHolderValueMap) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeHolderValueMap.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeHolderValueMap.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMap.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeHolderValueMap.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](stakeHolderValueMap.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeHolderValueMap.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeHolderValueMap.Name)); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](stakeHolderValueMap.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMap.RevisionNumber)); - jsonObject.Add("settings", this.PropertySerializerMap["settings"](stakeHolderValueMap.Settings)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeHolderValueMap.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMap.ThingPreference)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goal": + var allowedVersionsForGoal = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGoal.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("goal"u8); + + if(value is IEnumerable objectListGoal) + { + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requirement": + var allowedVersionsForRequirement = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRequirement.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirement"u8); + + if(value is IEnumerable objectListRequirement) + { + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "settings": + var allowedVersionsForSettings = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSettings.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("settings"u8); + + if(value is IEnumerable objectListSettings) + { + foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + var allowedVersionsForStakeholderValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + var allowedVersionsForValueGroup = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueGroup.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueGroup"u8); + + if(value is IEnumerable objectListValueGroup) + { + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not StakeHolderValueMap stakeHolderValueMap) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); + return; } - var stakeHolderValueMap = thing as StakeHolderValueMap; - if (stakeHolderValueMap == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMap."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeHolderValueMap.Actor.HasValue) + { + writer.WriteStringValue(stakeHolderValueMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(stakeHolderValueMap); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 9ac71efda..5d4612705 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMapSettings = CDP4Common.DTO.StakeHolderValueMapSettings; /// /// The purpose of the class is to provide a specific serializer @@ -44,71 +50,520 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSettingsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goalToValueGroupRelationship", goalToValueGroupRelationship => new JValue(goalToValueGroupRelationship) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "stakeholderValueToRequirementRelationship", stakeholderValueToRequirementRelationship => new JValue(stakeholderValueToRequirementRelationship) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroupToStakeholderValueRelationship", valueGroupToStakeholderValueRelationship => new JValue(valueGroupToStakeholderValueRelationship) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMapSettings stakeHolderValueMapSettings) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMapSettings.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goalToValueGroupRelationship", this.PropertySerializerMap["goalToValueGroupRelationship"](stakeHolderValueMapSettings.GoalToValueGroupRelationship)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMapSettings.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMapSettings.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMapSettings.RevisionNumber)); - jsonObject.Add("stakeholderValueToRequirementRelationship", this.PropertySerializerMap["stakeholderValueToRequirementRelationship"](stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMapSettings.ThingPreference)); - jsonObject.Add("valueGroupToStakeholderValueRelationship", this.PropertySerializerMap["valueGroupToStakeholderValueRelationship"](stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goaltovaluegrouprelationship": + var allowedVersionsForGoalToValueGroupRelationship = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForGoalToValueGroupRelationship.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervaluetorequirementrelationship": + var allowedVersionsForStakeholderValueToRequirementRelationship = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholderValueToRequirementRelationship.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegrouptostakeholdervaluerelationship": + var allowedVersionsForValueGroupToStakeholderValueRelationship = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValueGroupToStakeholderValueRelationship.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMapSettings"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not StakeHolderValueMapSettings stakeHolderValueMapSettings) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); + return; } - var stakeHolderValueMapSettings = thing as StakeHolderValueMapSettings; - if (stakeHolderValueMapSettings == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMapSettings."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeHolderValueMapSettings.Actor.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(stakeHolderValueMapSettings); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 418a744e9..fcde18fc7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Stakeholder = CDP4Common.DTO.Stakeholder; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,653 @@ namespace CDP4JsonSerializer public class StakeholderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Stakeholder stakeholder) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholder.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholder.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholder.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholder.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholder.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholder.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholder.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholder.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeholder.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholder.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + var allowedVersionsForStakeholderValue = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Stakeholder"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Stakeholder stakeholder) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); } - var stakeholder = thing as Stakeholder; - if (stakeholder == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Stakeholder."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholder.Actor.HasValue) + { + writer.WriteStringValue(stakeholder.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(stakeholder); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index aeafd65c6..7a7afb846 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeholderValue = CDP4Common.DTO.StakeholderValue; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,604 @@ namespace CDP4JsonSerializer public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeholderValue stakeholderValue) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholderValue.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholderValue.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholderValue.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholderValue.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholderValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholderValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholderValue.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholderValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholderValue.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholderValue.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholderValue.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholderValue.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholderValue.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeholderValue"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); + return; } - var stakeholderValue = thing as StakeholderValue; - if (stakeholderValue == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a StakeholderValue."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholderValue.Actor.HasValue) + { + writer.WriteStringValue(stakeholderValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(stakeholderValue); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index 01d37ef4f..028bdf061 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TelephoneNumber = CDP4Common.DTO.TelephoneNumber; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,450 @@ namespace CDP4JsonSerializer public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JArray(vcardType) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TelephoneNumber telephoneNumber) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), telephoneNumber.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](telephoneNumber.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](telephoneNumber.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](telephoneNumber.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](telephoneNumber.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](telephoneNumber.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](telephoneNumber.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](telephoneNumber.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](telephoneNumber.VcardType.Select(e => Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardTelephoneNumberKind), e)))); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + var allowedVersionsForVcardType = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForVcardType.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("vcardType"u8); + + if(value is IEnumerable objectListVcardType) + { + foreach(var vcardTypeItem in objectListVcardType) + { + writer.WriteStringValue(((VcardTelephoneNumberKind)vcardTypeItem).ToString()); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TelephoneNumber"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); + return; } - var telephoneNumber = thing as TelephoneNumber; - if (telephoneNumber == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a TelephoneNumber."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(telephoneNumber.Actor.HasValue) + { + writer.WriteStringValue(telephoneNumber.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(telephoneNumber); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 73c9a4eeb..14e1340b2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Term = CDP4Common.DTO.Term; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,634 @@ namespace CDP4JsonSerializer public class TermSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Term term) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](term.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), term.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](term.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](term.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](term.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](term.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](term.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](term.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](term.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](term.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](term.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](term.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](term.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Term"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not Term term) + { + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); + return; } - var term = thing as Term; - if (term == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a Term."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(term.Actor.HasValue) + { + writer.WriteStringValue(term.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(term); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index c789489fe..9c1d07169 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextParameterType = CDP4Common.DTO.TextParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class TextParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TextParameterType textParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](textParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](textParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](textParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](textParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](textParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](textParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not TextParameterType textParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); } - var textParameterType = thing as TextParameterType; - if (textParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a TextParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(textParameterType.Actor.HasValue) + { + writer.WriteStringValue(textParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(textParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index fd66640d1..168f24037 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextualNote = CDP4Common.DTO.TextualNote; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,581 @@ namespace CDP4JsonSerializer public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TextualNote textualNote) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](textualNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textualNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](textualNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](textualNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textualNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textualNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textualNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](textualNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textualNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textualNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](textualNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textualNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textualNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textualNote.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + var allowedVersionsForContent = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForContent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + var allowedVersionsForCreatedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + var allowedVersionsForLanguageCode = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + var allowedVersionsForOwner = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForOwner.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextualNote"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not TextualNote textualNote) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); } - var textualNote = thing as TextualNote; - if (textualNote == null) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new InvalidOperationException("The thing is not a TextualNote."); + Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(textualNote.Actor.HasValue) + { + writer.WriteStringValue(textualNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(textualNote); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index bacae9364..a2f051dc4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TimeOfDayParameterType = CDP4Common.DTO.TimeOfDayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -44,81 +50,726 @@ namespace CDP4JsonSerializer public class TimeOfDayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TimeOfDayParameterType timeOfDayParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](timeOfDayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](timeOfDayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), timeOfDayParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](timeOfDayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](timeOfDayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](timeOfDayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](timeOfDayParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](timeOfDayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](timeOfDayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](timeOfDayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](timeOfDayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](timeOfDayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](timeOfDayParameterType.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + var allowedVersionsForSymbol = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForSymbol.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TimeOfDayParameterType"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not TimeOfDayParameterType timeOfDayParameterType) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); } - var timeOfDayParameterType = thing as TimeOfDayParameterType; - if (timeOfDayParameterType == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a TimeOfDayParameterType."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(timeOfDayParameterType.Actor.HasValue) + { + writer.WriteStringValue(timeOfDayParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(timeOfDayParameterType); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 269622ccd..5e5c72687 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitFactor = CDP4Common.DTO.UnitFactor; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UnitFactor unitFactor) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](unitFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitFactor.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitFactor.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](unitFactor.Unit)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + var allowedVersionsForExponent = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExponent.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + var allowedVersionsForUnit = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForUnit.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitFactor"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not UnitFactor unitFactor) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); } - var unitFactor = thing as UnitFactor; - if (unitFactor == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a UnitFactor."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(unitFactor.Actor.HasValue) + { + writer.WriteStringValue(unitFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(unitFactor); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 9d93d94d0..dfbf4c97d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitPrefix = CDP4Common.DTO.UnitPrefix; /// /// The purpose of the class is to provide a specific serializer @@ -44,79 +50,668 @@ namespace CDP4JsonSerializer public class UnitPrefixSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UnitPrefix unitPrefix) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](unitPrefix.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitPrefix.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](unitPrefix.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](unitPrefix.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitPrefix.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitPrefix.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](unitPrefix.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitPrefix.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](unitPrefix.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitPrefix.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](unitPrefix.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitPrefix.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](unitPrefix.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitPrefix.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + var allowedVersionsForConversionFactor = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForConversionFactor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + var allowedVersionsForIsDeprecated = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitPrefix"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not UnitPrefix unitPrefix) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); } - var unitPrefix = thing as UnitPrefix; - if (unitPrefix == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - throw new InvalidOperationException("The thing is not a UnitPrefix."); + Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(unitPrefix.Actor.HasValue) + { + writer.WriteStringValue(unitPrefix.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(unitPrefix); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index a17a3a926..2e84713ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserPreference = CDP4Common.DTO.UserPreference; /// /// The purpose of the class is to provide a specific serializer @@ -44,69 +50,426 @@ namespace CDP4JsonSerializer public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UserPreference userPreference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userPreference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userPreference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userPreference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userPreference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userPreference.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userPreference.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](userPreference.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userPreference.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](userPreference.Value)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + var allowedVersionsForValue = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForValue.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserPreference"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not UserPreference userPreference) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); } - var userPreference = thing as UserPreference; - if (userPreference == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a UserPreference."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userPreference.Actor.HasValue) + { + writer.WriteStringValue(userPreference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(userPreference); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index e1a4946c4..2341cbf1f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserRuleVerification = CDP4Common.DTO.UserRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -44,74 +50,588 @@ namespace CDP4JsonSerializer public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JValue(rule) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UserRuleVerification userRuleVerification) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](userRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](userRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userRuleVerification.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userRuleVerification.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](userRuleVerification.Rule)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), userRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userRuleVerification.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "executedon": + var allowedVersionsForExecutedOn = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExecutedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + var allowedVersionsForIsActive = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIsActive.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + var allowedVersionsForRule = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRule.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("rule"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + var allowedVersionsForStatus = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForStatus.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violation": + var allowedVersionsForViolation = new List + { + "1.0.0", + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForViolation.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violation"u8); + + if(value is IEnumerable objectListViolation) + { + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserRuleVerification"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not UserRuleVerification userRuleVerification) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); } - var userRuleVerification = thing as UserRuleVerification; - if (userRuleVerification == null) + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a UserRuleVerification."); + case "1.0.0": + Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(userRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(userRuleVerification); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index a1853c804..81d529ef1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2022 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,14 +29,20 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ValueGroup = CDP4Common.DTO.ValueGroup; /// /// The purpose of the class is to provide a specific serializer @@ -44,77 +50,604 @@ namespace CDP4JsonSerializer public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serialize a value for a property into a /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + var requestedVersion = requestedDataModelVersion.ToString(3); - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ValueGroup valueGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](valueGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](valueGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), valueGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](valueGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](valueGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](valueGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](valueGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](valueGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](valueGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](valueGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](valueGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](valueGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](valueGroup.ThingPreference)); - return jsonObject; - } + switch(propertyName.ToLower()) + { + case "actor": + var allowedVersionsForActor = new List + { + "1.3.0", + }; - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + if(!allowedVersionsForActor.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + var allowedVersionsForAlias = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForAlias.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + var allowedVersionsForCategory = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForCategory.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + var allowedVersionsForClassKind = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForClassKind.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + var allowedVersionsForDefinition = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForDefinition.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + var allowedVersionsForExcludedDomain = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + var allowedVersionsForExcludedPerson = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + var allowedVersionsForHyperLink = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + var allowedVersionsForIid = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForIid.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + var allowedVersionsForModifiedOn = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + var allowedVersionsForName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + var allowedVersionsForRevisionNumber = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + var allowedVersionsForShortName = new List + { + "1.1.0", + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForShortName.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + var allowedVersionsForThingPreference = new List + { + "1.2.0", + "1.3.0", + }; + + if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ValueGroup"); + } } /// - /// Serialize the to JObject + /// Serializes a into an /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); + return; } - var valueGroup = thing as ValueGroup; - if (valueGroup == null) + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) { - throw new InvalidOperationException("The thing is not a ValueGroup."); + case "1.1.0": + Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(valueGroup.Actor.HasValue) + { + writer.WriteStringValue(valueGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); } - return this.Serialize(valueGroup); + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs new file mode 100644 index 000000000..f1d450c52 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ActualFiniteStateKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ActualFiniteStateKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "MANDATORY" => ActualFiniteStateKind.MANDATORY, + "FORBIDDEN" => ActualFiniteStateKind.FORBIDDEN, + _ => throw new InvalidDataException($"{value} is not a valid for ActualFiniteStateKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs new file mode 100644 index 000000000..4102f47fd --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationApprovalKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationApprovalKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ACCEPTED" => AnnotationApprovalKind.ACCEPTED, + "REJECTED" => AnnotationApprovalKind.REJECTED, + "WITHDRAWN" => AnnotationApprovalKind.WITHDRAWN, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationApprovalKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs new file mode 100644 index 000000000..d9ae34f96 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationClassificationKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationClassificationKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "MAJOR" => AnnotationClassificationKind.MAJOR, + "MINOR" => AnnotationClassificationKind.MINOR, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationClassificationKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs new file mode 100644 index 000000000..2448faab9 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs @@ -0,0 +1,68 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationStatusKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationStatusKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "OPEN" => AnnotationStatusKind.OPEN, + "DONE" => AnnotationStatusKind.DONE, + "CLOSED" => AnnotationStatusKind.CLOSED, + "INVALID" => AnnotationStatusKind.INVALID, + "WONTFIX" => AnnotationStatusKind.WONTFIX, + "NOT_APPLICABLE" => AnnotationStatusKind.NOT_APPLICABLE, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationStatusKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs new file mode 100644 index 000000000..850f139b5 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class BooleanOperatorKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static BooleanOperatorKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "AND" => BooleanOperatorKind.AND, + "OR" => BooleanOperatorKind.OR, + "XOR" => BooleanOperatorKind.XOR, + _ => throw new InvalidDataException($"{value} is not a valid for BooleanOperatorKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs new file mode 100644 index 000000000..cca7ec8a5 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs @@ -0,0 +1,243 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ClassKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ClassKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ActionItem" => ClassKind.ActionItem, + "ActualFiniteState" => ClassKind.ActualFiniteState, + "ActualFiniteStateList" => ClassKind.ActualFiniteStateList, + "Alias" => ClassKind.Alias, + "AndExpression" => ClassKind.AndExpression, + "Approval" => ClassKind.Approval, + "ArrayParameterType" => ClassKind.ArrayParameterType, + "BinaryNote" => ClassKind.BinaryNote, + "BinaryRelationship" => ClassKind.BinaryRelationship, + "BinaryRelationshipRule" => ClassKind.BinaryRelationshipRule, + "Book" => ClassKind.Book, + "BooleanExpression" => ClassKind.BooleanExpression, + "BooleanParameterType" => ClassKind.BooleanParameterType, + "Bounds" => ClassKind.Bounds, + "BuiltInRuleVerification" => ClassKind.BuiltInRuleVerification, + "Category" => ClassKind.Category, + "ChangeProposal" => ClassKind.ChangeProposal, + "ChangeRequest" => ClassKind.ChangeRequest, + "Citation" => ClassKind.Citation, + "Color" => ClassKind.Color, + "CommonFileStore" => ClassKind.CommonFileStore, + "CompoundParameterType" => ClassKind.CompoundParameterType, + "Constant" => ClassKind.Constant, + "ContractChangeNotice" => ClassKind.ContractChangeNotice, + "ContractDeviation" => ClassKind.ContractDeviation, + "ConversionBasedUnit" => ClassKind.ConversionBasedUnit, + "CyclicRatioScale" => ClassKind.CyclicRatioScale, + "DateParameterType" => ClassKind.DateParameterType, + "DateTimeParameterType" => ClassKind.DateTimeParameterType, + "DecompositionRule" => ClassKind.DecompositionRule, + "DefinedThing" => ClassKind.DefinedThing, + "Definition" => ClassKind.Definition, + "DependentParameterTypeAssignment" => ClassKind.DependentParameterTypeAssignment, + "DerivedQuantityKind" => ClassKind.DerivedQuantityKind, + "DerivedUnit" => ClassKind.DerivedUnit, + "DiagramCanvas" => ClassKind.DiagramCanvas, + "DiagramEdge" => ClassKind.DiagramEdge, + "DiagramElementContainer" => ClassKind.DiagramElementContainer, + "DiagramElementThing" => ClassKind.DiagramElementThing, + "DiagrammingStyle" => ClassKind.DiagrammingStyle, + "DiagramObject" => ClassKind.DiagramObject, + "DiagramShape" => ClassKind.DiagramShape, + "DiagramThingBase" => ClassKind.DiagramThingBase, + "DiscussionItem" => ClassKind.DiscussionItem, + "DomainFileStore" => ClassKind.DomainFileStore, + "DomainOfExpertise" => ClassKind.DomainOfExpertise, + "DomainOfExpertiseGroup" => ClassKind.DomainOfExpertiseGroup, + "ElementBase" => ClassKind.ElementBase, + "ElementDefinition" => ClassKind.ElementDefinition, + "ElementUsage" => ClassKind.ElementUsage, + "EmailAddress" => ClassKind.EmailAddress, + "EngineeringModel" => ClassKind.EngineeringModel, + "EngineeringModelDataAnnotation" => ClassKind.EngineeringModelDataAnnotation, + "EngineeringModelDataDiscussionItem" => ClassKind.EngineeringModelDataDiscussionItem, + "EngineeringModelDataNote" => ClassKind.EngineeringModelDataNote, + "EngineeringModelSetup" => ClassKind.EngineeringModelSetup, + "EnumerationParameterType" => ClassKind.EnumerationParameterType, + "EnumerationValueDefinition" => ClassKind.EnumerationValueDefinition, + "ExclusiveOrExpression" => ClassKind.ExclusiveOrExpression, + "ExternalIdentifierMap" => ClassKind.ExternalIdentifierMap, + "File" => ClassKind.File, + "FileRevision" => ClassKind.FileRevision, + "FileStore" => ClassKind.FileStore, + "FileType" => ClassKind.FileType, + "Folder" => ClassKind.Folder, + "GenericAnnotation" => ClassKind.GenericAnnotation, + "Glossary" => ClassKind.Glossary, + "Goal" => ClassKind.Goal, + "HyperLink" => ClassKind.HyperLink, + "IdCorrespondence" => ClassKind.IdCorrespondence, + "IndependentParameterTypeAssignment" => ClassKind.IndependentParameterTypeAssignment, + "IntervalScale" => ClassKind.IntervalScale, + "Iteration" => ClassKind.Iteration, + "IterationSetup" => ClassKind.IterationSetup, + "LinearConversionUnit" => ClassKind.LinearConversionUnit, + "LogarithmicScale" => ClassKind.LogarithmicScale, + "LogEntryChangelogItem" => ClassKind.LogEntryChangelogItem, + "MappingToReferenceScale" => ClassKind.MappingToReferenceScale, + "MeasurementScale" => ClassKind.MeasurementScale, + "MeasurementUnit" => ClassKind.MeasurementUnit, + "ModellingAnnotationItem" => ClassKind.ModellingAnnotationItem, + "ModellingThingReference" => ClassKind.ModellingThingReference, + "ModelLogEntry" => ClassKind.ModelLogEntry, + "ModelReferenceDataLibrary" => ClassKind.ModelReferenceDataLibrary, + "MultiRelationship" => ClassKind.MultiRelationship, + "MultiRelationshipRule" => ClassKind.MultiRelationshipRule, + "NaturalLanguage" => ClassKind.NaturalLanguage, + "NestedElement" => ClassKind.NestedElement, + "NestedParameter" => ClassKind.NestedParameter, + "Note" => ClassKind.Note, + "NotExpression" => ClassKind.NotExpression, + "NotThing" => ClassKind.NotThing, + "Option" => ClassKind.Option, + "OrdinalScale" => ClassKind.OrdinalScale, + "OrExpression" => ClassKind.OrExpression, + "Organization" => ClassKind.Organization, + "OrganizationalParticipant" => ClassKind.OrganizationalParticipant, + "OwnedStyle" => ClassKind.OwnedStyle, + "Page" => ClassKind.Page, + "Parameter" => ClassKind.Parameter, + "ParameterBase" => ClassKind.ParameterBase, + "ParameterGroup" => ClassKind.ParameterGroup, + "ParameterizedCategoryRule" => ClassKind.ParameterizedCategoryRule, + "ParameterOrOverrideBase" => ClassKind.ParameterOrOverrideBase, + "ParameterOverride" => ClassKind.ParameterOverride, + "ParameterOverrideValueSet" => ClassKind.ParameterOverrideValueSet, + "ParameterSubscription" => ClassKind.ParameterSubscription, + "ParameterSubscriptionValueSet" => ClassKind.ParameterSubscriptionValueSet, + "ParameterType" => ClassKind.ParameterType, + "ParameterTypeComponent" => ClassKind.ParameterTypeComponent, + "ParameterValue" => ClassKind.ParameterValue, + "ParameterValueSet" => ClassKind.ParameterValueSet, + "ParameterValueSetBase" => ClassKind.ParameterValueSetBase, + "ParametricConstraint" => ClassKind.ParametricConstraint, + "Participant" => ClassKind.Participant, + "ParticipantPermission" => ClassKind.ParticipantPermission, + "ParticipantRole" => ClassKind.ParticipantRole, + "Person" => ClassKind.Person, + "PersonPermission" => ClassKind.PersonPermission, + "PersonRole" => ClassKind.PersonRole, + "Point" => ClassKind.Point, + "PossibleFiniteState" => ClassKind.PossibleFiniteState, + "PossibleFiniteStateList" => ClassKind.PossibleFiniteStateList, + "PrefixedUnit" => ClassKind.PrefixedUnit, + "Publication" => ClassKind.Publication, + "QuantityKind" => ClassKind.QuantityKind, + "QuantityKindFactor" => ClassKind.QuantityKindFactor, + "RatioScale" => ClassKind.RatioScale, + "ReferenceDataLibrary" => ClassKind.ReferenceDataLibrary, + "ReferencerRule" => ClassKind.ReferencerRule, + "ReferenceSource" => ClassKind.ReferenceSource, + "RelationalExpression" => ClassKind.RelationalExpression, + "Relationship" => ClassKind.Relationship, + "RelationshipParameterValue" => ClassKind.RelationshipParameterValue, + "RequestForDeviation" => ClassKind.RequestForDeviation, + "RequestForWaiver" => ClassKind.RequestForWaiver, + "Requirement" => ClassKind.Requirement, + "RequirementsContainer" => ClassKind.RequirementsContainer, + "RequirementsContainerParameterValue" => ClassKind.RequirementsContainerParameterValue, + "RequirementsGroup" => ClassKind.RequirementsGroup, + "RequirementsSpecification" => ClassKind.RequirementsSpecification, + "ReviewItemDiscrepancy" => ClassKind.ReviewItemDiscrepancy, + "Rule" => ClassKind.Rule, + "RuleVerification" => ClassKind.RuleVerification, + "RuleVerificationList" => ClassKind.RuleVerificationList, + "RuleViolation" => ClassKind.RuleViolation, + "SampledFunctionParameterType" => ClassKind.SampledFunctionParameterType, + "ScalarParameterType" => ClassKind.ScalarParameterType, + "ScaleReferenceQuantityValue" => ClassKind.ScaleReferenceQuantityValue, + "ScaleValueDefinition" => ClassKind.ScaleValueDefinition, + "Section" => ClassKind.Section, + "SharedStyle" => ClassKind.SharedStyle, + "SimpleParameterizableThing" => ClassKind.SimpleParameterizableThing, + "SimpleParameterValue" => ClassKind.SimpleParameterValue, + "SimpleQuantityKind" => ClassKind.SimpleQuantityKind, + "SimpleUnit" => ClassKind.SimpleUnit, + "SiteDirectory" => ClassKind.SiteDirectory, + "SiteDirectoryDataAnnotation" => ClassKind.SiteDirectoryDataAnnotation, + "SiteDirectoryDataDiscussionItem" => ClassKind.SiteDirectoryDataDiscussionItem, + "SiteDirectoryThingReference" => ClassKind.SiteDirectoryThingReference, + "SiteLogEntry" => ClassKind.SiteLogEntry, + "SiteReferenceDataLibrary" => ClassKind.SiteReferenceDataLibrary, + "Solution" => ClassKind.Solution, + "SpecializedQuantityKind" => ClassKind.SpecializedQuantityKind, + "Stakeholder" => ClassKind.Stakeholder, + "StakeholderValue" => ClassKind.StakeholderValue, + "StakeHolderValueMap" => ClassKind.StakeHolderValueMap, + "StakeHolderValueMapSettings" => ClassKind.StakeHolderValueMapSettings, + "TelephoneNumber" => ClassKind.TelephoneNumber, + "Term" => ClassKind.Term, + "TextParameterType" => ClassKind.TextParameterType, + "TextualNote" => ClassKind.TextualNote, + "Thing" => ClassKind.Thing, + "ThingReference" => ClassKind.ThingReference, + "TimeOfDayParameterType" => ClassKind.TimeOfDayParameterType, + "TopContainer" => ClassKind.TopContainer, + "UnitFactor" => ClassKind.UnitFactor, + "UnitPrefix" => ClassKind.UnitPrefix, + "UserPreference" => ClassKind.UserPreference, + "UserRuleVerification" => ClassKind.UserRuleVerification, + "ValueGroup" => ClassKind.ValueGroup, + _ => throw new InvalidDataException($"{value} is not a valid for ClassKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs new file mode 100644 index 000000000..d0990d71e --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class EngineeringModelKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static EngineeringModelKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "STUDY_MODEL" => EngineeringModelKind.STUDY_MODEL, + "TEMPLATE_MODEL" => EngineeringModelKind.TEMPLATE_MODEL, + "MODEL_CATALOGUE" => EngineeringModelKind.MODEL_CATALOGUE, + "SCRATCH_MODEL" => EngineeringModelKind.SCRATCH_MODEL, + _ => throw new InvalidDataException($"{value} is not a valid for EngineeringModelKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs new file mode 100644 index 000000000..f8d5372d9 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class InterfaceEndKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static InterfaceEndKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NONE" => InterfaceEndKind.NONE, + "UNDIRECTED" => InterfaceEndKind.UNDIRECTED, + "INPUT" => InterfaceEndKind.INPUT, + "OUTPUT" => InterfaceEndKind.OUTPUT, + "IN_OUT" => InterfaceEndKind.IN_OUT, + _ => throw new InvalidDataException($"{value} is not a valid for InterfaceEndKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs new file mode 100644 index 000000000..a5be3bc32 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogEntryChangelogItemKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogEntryChangelogItemKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ADD" => LogEntryChangelogItemKind.ADD, + "UPDATE" => LogEntryChangelogItemKind.UPDATE, + "DELETE" => LogEntryChangelogItemKind.DELETE, + _ => throw new InvalidDataException($"{value} is not a valid for LogEntryChangelogItemKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs new file mode 100644 index 000000000..96f9c0dbe --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogLevelKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogLevelKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "TRACE" => LogLevelKind.TRACE, + "DEBUG" => LogLevelKind.DEBUG, + "INFO" => LogLevelKind.INFO, + "USER" => LogLevelKind.USER, + _ => throw new InvalidDataException($"{value} is not a valid for LogLevelKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs new file mode 100644 index 000000000..5f132393b --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogarithmBaseKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogarithmBaseKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NATURAL" => LogarithmBaseKind.NATURAL, + "BASE2" => LogarithmBaseKind.BASE2, + "BASE10" => LogarithmBaseKind.BASE10, + _ => throw new InvalidDataException($"{value} is not a valid for LogarithmBaseKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs new file mode 100644 index 000000000..c2305d32f --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class NumberSetKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static NumberSetKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NATURAL_NUMBER_SET" => NumberSetKind.NATURAL_NUMBER_SET, + "INTEGER_NUMBER_SET" => NumberSetKind.INTEGER_NUMBER_SET, + "RATIONAL_NUMBER_SET" => NumberSetKind.RATIONAL_NUMBER_SET, + "REAL_NUMBER_SET" => NumberSetKind.REAL_NUMBER_SET, + _ => throw new InvalidDataException($"{value} is not a valid for NumberSetKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs new file mode 100644 index 000000000..1dc6fcd34 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ParameterSwitchKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ParameterSwitchKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "COMPUTED" => ParameterSwitchKind.COMPUTED, + "MANUAL" => ParameterSwitchKind.MANUAL, + "REFERENCE" => ParameterSwitchKind.REFERENCE, + _ => throw new InvalidDataException($"{value} is not a valid for ParameterSwitchKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs new file mode 100644 index 000000000..451150651 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ParticipantAccessRightKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ParticipantAccessRightKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NOT_APPLICABLE" => ParticipantAccessRightKind.NOT_APPLICABLE, + "NONE" => ParticipantAccessRightKind.NONE, + "SAME_AS_CONTAINER" => ParticipantAccessRightKind.SAME_AS_CONTAINER, + "SAME_AS_SUPERCLASS" => ParticipantAccessRightKind.SAME_AS_SUPERCLASS, + "READ" => ParticipantAccessRightKind.READ, + "MODIFY" => ParticipantAccessRightKind.MODIFY, + "MODIFY_IF_OWNER" => ParticipantAccessRightKind.MODIFY_IF_OWNER, + _ => throw new InvalidDataException($"{value} is not a valid for ParticipantAccessRightKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs new file mode 100644 index 000000000..331bbf18c --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs @@ -0,0 +1,71 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class PersonAccessRightKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static PersonAccessRightKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NOT_APPLICABLE" => PersonAccessRightKind.NOT_APPLICABLE, + "NONE" => PersonAccessRightKind.NONE, + "SAME_AS_CONTAINER" => PersonAccessRightKind.SAME_AS_CONTAINER, + "SAME_AS_SUPERCLASS" => PersonAccessRightKind.SAME_AS_SUPERCLASS, + "READ" => PersonAccessRightKind.READ, + "MODIFY" => PersonAccessRightKind.MODIFY, + "READ_IF_PARTICIPANT" => PersonAccessRightKind.READ_IF_PARTICIPANT, + "MODIFY_IF_PARTICIPANT" => PersonAccessRightKind.MODIFY_IF_PARTICIPANT, + "MODIFY_OWN_PERSON" => PersonAccessRightKind.MODIFY_OWN_PERSON, + _ => throw new InvalidDataException($"{value} is not a valid for PersonAccessRightKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs new file mode 100644 index 000000000..5cdf396be --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs @@ -0,0 +1,68 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class RelationalOperatorKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static RelationalOperatorKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "EQ" => RelationalOperatorKind.EQ, + "NE" => RelationalOperatorKind.NE, + "LT" => RelationalOperatorKind.LT, + "GT" => RelationalOperatorKind.GT, + "LE" => RelationalOperatorKind.LE, + "GE" => RelationalOperatorKind.GE, + _ => throw new InvalidDataException($"{value} is not a valid for RelationalOperatorKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs new file mode 100644 index 000000000..9f73e8c37 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class RuleVerificationStatusKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static RuleVerificationStatusKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NONE" => RuleVerificationStatusKind.NONE, + "PASSED" => RuleVerificationStatusKind.PASSED, + "FAILED" => RuleVerificationStatusKind.FAILED, + "INCONCLUSIVE" => RuleVerificationStatusKind.INCONCLUSIVE, + _ => throw new InvalidDataException($"{value} is not a valid for RuleVerificationStatusKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs new file mode 100644 index 000000000..0bbad8cc7 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class StudyPhaseKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static StudyPhaseKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "PREPARATION_PHASE" => StudyPhaseKind.PREPARATION_PHASE, + "DESIGN_SESSION_PHASE" => StudyPhaseKind.DESIGN_SESSION_PHASE, + "REPORTING_PHASE" => StudyPhaseKind.REPORTING_PHASE, + "COMPLETED_STUDY" => StudyPhaseKind.COMPLETED_STUDY, + _ => throw new InvalidDataException($"{value} is not a valid for StudyPhaseKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs new file mode 100644 index 000000000..4fb8c099d --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class VcardEmailAddressKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static VcardEmailAddressKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "WORK" => VcardEmailAddressKind.WORK, + "HOME" => VcardEmailAddressKind.HOME, + _ => throw new InvalidDataException($"{value} is not a valid for VcardEmailAddressKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs new file mode 100644 index 000000000..9048d9c7d --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs @@ -0,0 +1,71 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class VcardTelephoneNumberKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static VcardTelephoneNumberKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "WORK" => VcardTelephoneNumberKind.WORK, + "HOME" => VcardTelephoneNumberKind.HOME, + "VOICE" => VcardTelephoneNumberKind.VOICE, + "TEXT" => VcardTelephoneNumberKind.TEXT, + "FAX" => VcardTelephoneNumberKind.FAX, + "CELL" => VcardTelephoneNumberKind.CELL, + "PAGER" => VcardTelephoneNumberKind.PAGER, + "TEXTPHONE" => VcardTelephoneNumberKind.TEXTPHONE, + "VIDEO" => VcardTelephoneNumberKind.VIDEO, + _ => throw new InvalidDataException($"{value} is not a valid for VcardTelephoneNumberKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 761a6fdca..14c3d6b0f 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -7,26 +7,27 @@ 26.6.0 CDP4 JSON Serialization Library Copyright © RHEA System S.A. - Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael + Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Jaime, Antoine CDP4JsonSerializer-CE true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition - true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true cdp4-icon.png true true - snupkg https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git CDP COMET ECSS-E-TM-10-25 JSON LGPL-3.0-only [BUMP] To CDP4Common 26.6.0 - README.md + 11.0 + + @@ -36,21 +37,10 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/CDP4JsonSerializer/Cdp4JsonSerializer.cs b/CDP4JsonSerializer/Cdp4JsonSerializer.cs index 349731f91..2d72690bf 100644 --- a/CDP4JsonSerializer/Cdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4JsonSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { @@ -28,17 +28,15 @@ namespace CDP4JsonSerializer using System.Collections.Generic; using System.Diagnostics; using System.IO; + using System.Text.Json; + using System.Text.Json.Serialization; using CDP4Common.MetaInfo; using CDP4JsonSerializer.JsonConverter; - using Newtonsoft.Json; - using Newtonsoft.Json.Converters; - using Newtonsoft.Json.Serialization; - using NLog; - + using Thing = CDP4Common.DTO.Thing; /// @@ -52,7 +50,7 @@ public class Cdp4JsonSerializer : ICdp4JsonSerializer private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The meta Info Provider. @@ -66,12 +64,17 @@ public Cdp4JsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedV } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Cdp4JsonSerializer() { } + /// + /// Gets or sets the options for the serializer + /// + public JsonSerializerOptions JsonSerializerOptions { get; private set; } + /// /// Gets or sets the data model version for this request. /// @@ -83,14 +86,19 @@ public Cdp4JsonSerializer() public IMetaDataProvider MetaInfoProvider { get; private set; } /// - /// Initialize this instance with the required and supported + /// Initialize this instance with the required and supported /// - /// The - /// The supported - public void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) + /// The + /// The supported + public virtual void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) { this.MetaInfoProvider = metaInfoProvider; this.RequestDataModelVersion = supportedVersion; + + this.JsonSerializerOptions = SerializerOptions.Copy(); + this.JsonSerializerOptions.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false)); } /// @@ -115,31 +123,25 @@ public void SerializeToStream(object collectionSource, Stream outputStream) } var sw = Stopwatch.StartNew(); - - var serializer = this.CreateJsonSerializer(); - Logger.Trace("initializing JsonTextWriter"); - var jsonWriter = new JsonTextWriter(new StreamWriter(outputStream)); - - Logger.Trace("Serialize to JsonTextWriter"); - serializer.Serialize(jsonWriter, collectionSource); - jsonWriter.Flush(); + Logger.Trace("initializing Serialization"); + JsonSerializer.Serialize(outputStream, collectionSource, this.JsonSerializerOptions); sw.Stop(); Logger.Debug("SerializeToStream finished in {0} [ms]", sw.ElapsedMilliseconds); } /// - /// Serialize the to a JSON stream + /// Serialize the to a JSON stream /// /// - /// The + /// The /// /// /// The output stream to which the serialized JSON objects are written /// /// - /// A value indicating whether the contained shall be included in the JSON stream + /// A value indicating whether the contained shall be included in the JSON stream /// /// A JSON stream public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputStream, bool isExtentDeep) @@ -160,9 +162,11 @@ public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputS } var dtos = new List(); + if (isExtentDeep) { var pocos = source.QueryContainedThingsDeep(); + foreach (var poco in pocos) { dtos.Add(poco.ToDto()); @@ -179,10 +183,10 @@ public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputS } /// - /// Serialize the to a JSON string + /// Serialize the to a JSON string /// - /// The - /// A value indicating whether the contained shall be processed + /// The + /// A value indicating whether the contained shall be processed /// The JSON string public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExtentDeep) { @@ -190,27 +194,24 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten { throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); } - - string jsonString; + Logger.Trace("initializing MemoryStream"); - using (var stream = new MemoryStream()) - { - this.SerializeToStream(source, stream, isExtentDeep); + using var stream = new MemoryStream(); - Logger.Trace("rewind MemoryStream"); - stream.Position = 0; + this.SerializeToStream(source, stream, isExtentDeep); - Logger.Trace("initializing StreamReader"); - using (var reader = new StreamReader(stream)) - { - var sw = new Stopwatch(); - sw.Start(); - jsonString = reader.ReadToEnd(); - sw.Stop(); - Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); - } - } + Logger.Trace("rewind MemoryStream"); + stream.Position = 0; + + Logger.Trace("initializing StreamReader"); + using var reader = new StreamReader(stream); + + var sw = new Stopwatch(); + sw.Start(); + var jsonString = reader.ReadToEnd(); + sw.Stop(); + Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); return jsonString; } @@ -222,7 +223,7 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten /// The content Stream. /// /// - /// The the deserialized collection of . + /// The the deserialized collection of . /// public IEnumerable Deserialize(Stream contentStream) { @@ -248,43 +249,48 @@ public T Deserialize(Stream contentStream) throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); } - var serializer = this.CreateJsonSerializer(); - - T data; - using (var streamReader = new StreamReader(contentStream)) - using (var jsonTextReader = new JsonTextReader(streamReader)) - { - var sw = new Stopwatch(); - sw.Start(); - data = serializer.Deserialize(jsonTextReader); - Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); - } - + var sw = new Stopwatch(); + sw.Start(); + var data = JsonSerializer.Deserialize(contentStream, this.JsonSerializerOptions); + Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); return data; } /// - /// Create a + /// Serialize an object into a string /// - /// - /// an instance of - /// - protected JsonSerializer CreateJsonSerializer() + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + public string SerializeToString(object toSerialize) { - Logger.Trace("initializing JsonSerializer"); - var serializer = new JsonSerializer + if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; - - Logger.Trace("register converters"); - serializer.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - serializer.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - serializer.Converters.Add(new ClassKindConverter()); - serializer.Converters.Add(new StringEnumConverter()); - - return serializer; + throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); + } + + Logger.Trace("initializing MemoryStream"); + + using var stream = new MemoryStream(); + + this.SerializeToStream(toSerialize, stream); + + Logger.Trace("rewind MemoryStream"); + stream.Position = 0; + + Logger.Trace("initializing StreamReader"); + using var reader = new StreamReader(stream); + + var sw = new Stopwatch(); + sw.Start(); + var jsonString = reader.ReadToEnd(); + sw.Stop(); + Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); + + return jsonString; } } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs b/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs index ddff2cbdb..a10662dd8 100644 --- a/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs +++ b/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs @@ -1,46 +1,54 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; + using CDP4Common.Comparers; using CDP4Common.Types; + using NLog; + /// /// Abstract supertype from which all derive /// public abstract class BaseThingSerializer { + /// + /// The NLog logger + /// + protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + /// /// The used to compare 2 s /// - protected readonly GuidComparer guidComparer = new GuidComparer(); + protected readonly GuidComparer GuidComparer = new(); /// /// The used to compare 2 s /// - protected readonly OrderedItemComparer orderedItemComparer = new OrderedItemComparer(); + protected readonly OrderedItemComparer OrderedItemComparer = new(); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs index fee89b190..cd501b189 100644 --- a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs +++ b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs @@ -1,51 +1,56 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; - using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Nodes; using CDP4Common.DTO; - using Newtonsoft.Json.Linq; - /// - /// Definition of the used to serialize instances of to a + /// Definition of the used to serialize instances of to a + /// /// public interface IThingSerializer { /// - /// Gets the map containing the serialization method for each property + /// Serialize a value for a property into a /// - IReadOnlyDictionary> PropertySerializerMap { get; } + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - JObject Serialize(Thing thing); + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/Helper/SerializerHelper.cs b/CDP4JsonSerializer/Helper/SerializerHelper.cs index f7cd175de..c1f22cfc9 100644 --- a/CDP4JsonSerializer/Helper/SerializerHelper.cs +++ b/CDP4JsonSerializer/Helper/SerializerHelper.cs @@ -1,53 +1,56 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; using System.Collections.Generic; using System.Linq; + using System.Text.Json; using System.Text.RegularExpressions; using CDP4Common.Types; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - /// /// Utility method to convert a JSON token to a CDP4 type /// public static class SerializerHelper { + /// + /// Gets the format of the to use + /// + public const string DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffZ"; + /// /// Regex used for conversion of Json value to string /// - private static readonly Regex JsonToValueArrayRegex = new Regex(@"^\[(.*)\]$", RegexOptions.Singleline); - + private static readonly Regex JsonToValueArrayRegex = new(@"^\[(.*)\]$", RegexOptions.Singleline); + /// /// Regex used for conversion of HStore value to string /// - private static readonly Regex HstoreToValueArrayRegex = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); + private static readonly Regex HstoreToValueArrayRegex = new(@"^\{(.*)\}$", RegexOptions.Singleline); /// /// Convert a string to a @@ -78,44 +81,82 @@ public static string ToJsonString(this ValueArray valueArray) } /// - /// Serialize a to a + /// Writes an into an /// - /// The - /// The - public static JObject ToJsonObject(this OrderedItem orderedItem) + /// The + /// The to write + public static void WriteOrderedItem(this Utf8JsonWriter writer, OrderedItem orderedItem) { - var jsonObject = new JObject(); - jsonObject.Add("k", new JValue(orderedItem.K)); + writer.WriteStartObject(); + writer.WriteNumber("k"u8, orderedItem.K); if (orderedItem.M != null) { - jsonObject.Add("m", new JValue(orderedItem.M)); + writer.WriteNumber("m"u8, orderedItem.M.Value); + } + + writer.WritePropertyName("v"u8); + + switch (orderedItem.V) + { + case string stringValue: + writer.WriteStringValue(stringValue); + break; + case Guid guidValue: + writer.WriteStringValue(guidValue); + break; + case bool boolValue: + writer.WriteBooleanValue(boolValue); + break; + case int intValue: + writer.WriteNumberValue(intValue); + break; + case double doubleValue: + writer.WriteNumberValue(doubleValue); + break; + case float floatValue: + writer.WriteNumberValue(floatValue); + break; + default: + throw new NotSupportedException($"The type {orderedItem.V.GetType().Name} is not supported for the {nameof(OrderedItem)} serialization"); } - jsonObject.Add("v", new JValue(orderedItem.V)); - return jsonObject; + writer.WriteEndObject(); } /// - /// Instantiate a from a + /// Instantiate a from a /// - /// The + /// The /// The - public static IEnumerable ToOrderedItemCollection(this JToken jsonToken) + public static IEnumerable ToOrderedItemCollection(this JsonElement jsonToken) { var list = new List(); - foreach (var token in jsonToken) + + foreach (var prop in jsonToken.EnumerateArray()) { + var keyProp = prop.GetProperty("k"); + var valueKind = keyProp.ValueKind; + var key = long.MinValue; + + if (valueKind == JsonValueKind.String) + { + key = Convert.ToInt64(keyProp.GetString()); + } + else if (valueKind == JsonValueKind.Number) + { + key = keyProp.GetInt64(); + } + var orderedItem = new OrderedItem { - K = token["k"].ToObject(), - V = token["v"].ToString() + K = key, + V = prop.GetProperty("v").GetString(), }; - var move = token["m"]; - if (move != null) + if (prop.TryGetProperty("m", out var value) && value.ValueKind != JsonValueKind.Null) { - orderedItem.M = move.ToObject(); + orderedItem.M = value.GetInt64(); } list.Add(orderedItem); @@ -124,19 +165,6 @@ public static IEnumerable ToOrderedItemCollection(this JToken jsonT return list; } - /// - /// Assert Whether a is null or empty - /// - /// The - /// True if the is null or empty - public static bool IsNullOrEmpty(this JToken token) - { - return (token == null) || - (token.Type == JTokenType.Array && !token.HasValues) || - (token.Type == JTokenType.Object && !token.HasValues) || - (token.Type == JTokenType.Null); - } - /// /// Convert a string to a /// @@ -159,7 +187,7 @@ private static ValueArray ToValueArray(string valueArrayString, Regex rege foreach (Match match in test) { - stringValues.Add(JsonConvert.DeserializeObject($"\"{match.Groups[1].Value}\"")); + stringValues.Add(JsonSerializer.Deserialize($"\"{match.Groups[1].Value}\"")); } var convertedStringList = stringValues.Select(m => (T)Convert.ChangeType(m, typeof(T))).ToList(); @@ -189,7 +217,7 @@ private static IEnumerable ValueArrayToStringList(ValueArray val for (var i = 0; i < items.Count; i++) { - items[i] = $"{JsonConvert.SerializeObject(items[i])}"; + items[i] = $"{JsonSerializer.Serialize(items[i], SerializerOptions.Options)}"; } return items; diff --git a/CDP4JsonSerializer/ICdp4JsonSerializer.cs b/CDP4JsonSerializer/ICdp4JsonSerializer.cs index 26b86e066..79d3bb656 100644 --- a/CDP4JsonSerializer/ICdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/ICdp4JsonSerializer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { @@ -99,17 +99,14 @@ public interface ICdp4JsonSerializer IEnumerable Deserialize(Stream contentStream); /// - /// Convenience method that deserializes the passed in JSON content stream + /// Serialize an object into a string /// - /// - /// The type info for which deserialization will be performed - /// - /// - /// The content Stream. - /// - /// - /// The the deserialized instance of the specified Type - /// - T Deserialize(Stream contentStream); + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + string SerializeToString(object toSerialize); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs b/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs deleted file mode 100644 index 0db4d1766..000000000 --- a/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4JsonSerializer.JsonConverter -{ - using System; - - using CDP4Common.CommonData; - - using Newtonsoft.Json.Converters; - - /// - /// Specific converter for values. - /// - public class ClassKindConverter : StringEnumConverter - { - /// - /// Determines whether this instance can convert the specified object type. - /// - /// Type of the object. - /// - /// true if this instance can convert the specified object type; otherwise, false. - /// - public override bool CanConvert(Type objectType) - { - return objectType == typeof(ClassKind); - } - } -} diff --git a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs index e18948503..969d8bd09 100644 --- a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs @@ -1,47 +1,48 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.JsonConverter { using System; - using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Nodes; + using System.Text.Json.Serialization; + using CDP4Common; using CDP4Common.MetaInfo; using CDP4Common.Polyfills; + using CDP4JsonSerializer.Helper; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; + using NLog; using Dto = CDP4Common.DTO; /// - /// The for s + /// The for s /// - public class ClasslessDtoSerializer : JsonConverter + public class ClasslessDtoSerializer : JsonConverter { /// /// The NLog logger @@ -49,149 +50,96 @@ public class ClasslessDtoSerializer : JsonConverter private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// - /// The + /// The data model version for this request. /// - private readonly IMetaDataProvider metaDataProvider; + private readonly Version dataModelVersion; /// - /// The data model version for this request. + /// The /// - private readonly Version dataModelVersion; + private readonly IMetaDataProvider metaDataProvider; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The + /// The /// - /// The supported + /// The supported public ClasslessDtoSerializer(IMetaDataProvider metaDataProvider, Version dataModelVersion) { this.metaDataProvider = metaDataProvider; this.dataModelVersion = dataModelVersion; } - /// - /// Gets a value indicating whether this converter supports JSON read. - /// - public override bool CanRead - { - get { return true; } - } - - /// - /// Gets a value indicating whether this converter supports JSON write. - /// - public override bool CanWrite - { - get { return true; } - } - /// /// Override of the can convert type check. /// - /// + /// /// The object type. /// /// /// true if this converter is to be used. /// - public override bool CanConvert(Type objectType) + public override bool CanConvert(Type typeToConvert) { - return typeof(ClasslessDTO).QueryIsAssignableFrom(objectType); + return typeof(ClasslessDTO).QueryIsAssignableFrom(typeToConvert); } /// - /// Write JSON. + /// Tries to deserialize a JSON into a /// - /// - /// The JSON writer. - /// - /// - /// The value object. - /// - /// - /// The JSON serializer. - /// - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + /// the + /// the to convert + /// the options of the serializer + /// the + public override ClasslessDTO Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - var classlessDto = (ClasslessDTO)value; - - var typeName = classlessDto["ClassKind"].ToString(); - var classVersion = new Version(this.metaDataProvider.GetClassVersion(typeName)); - if (classVersion > this.dataModelVersion) - { - // skip type serialization if the data version is larger then the request data model version - return; - } - - var jsonObject = ((ClasslessDTO)value).ToJsonObject(); - - var nonSerializablePropeties = new List(); - foreach (var kvp in jsonObject) + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) { - var propertyVersion = new Version(this.metaDataProvider.GetPropertyVersion(typeName, Helper.Utils.CapitalizeFirstLetter(kvp.Key))); - if (propertyVersion > this.dataModelVersion) - { - nonSerializablePropeties.Add(kvp.Key); - } + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new NullReferenceException("The data object in the JSON array could not be cast to a JsonElement type."); } - foreach (var nonSerializablePropety in nonSerializablePropeties) - { - jsonObject.Remove(nonSerializablePropety); - } + var dto = jsonElement?.ToDto(); + var classlessDto = this.GenerateClasslessDto(jsonElement.Value, dto); - jsonObject.WriteTo(writer); + return classlessDto; } /// - /// Override of the Read JSON method. + /// Write a JSON /// - /// - /// The JSON reader. - /// - /// - /// The type information of the object. - /// - /// - /// The existing object value. - /// - /// - /// The JSON serializer. - /// - /// - /// A deserialized instance. - /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + /// the + /// the to serialize + /// the options of the serializer + public override void Write(Utf8JsonWriter writer, ClasslessDTO value, JsonSerializerOptions options) { - // load object from stream - var jsonObject = JObject.Load(reader); + var typeName = value["ClassKind"].ToString(); + var classVersion = new Version(this.metaDataProvider.GetClassVersion(typeName)); - if (jsonObject == null) + if (classVersion > this.dataModelVersion) { - Logger.Error("The data object in the JSON array could not be cast to a JObject type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JObject type."); + // skip type serialization if the data version is larger then the request data model version + return; } - var dto = jsonObject.ToDto(); - var classlessDto = this.GenerateClasslessDto(jsonObject, dto); - - return classlessDto; + value.SerializeClasslessDto(writer, this.dataModelVersion); } /// - /// Create a from a and a partial + /// Create a from a and a partial /// - /// The - /// The - /// The generated - private ClasslessDTO GenerateClasslessDto(JObject jsonObject, Dto.Thing dto) + /// The + /// The + /// The generated + private ClasslessDTO GenerateClasslessDto(JsonElement jsonObject, Dto.Thing dto) { var metainfo = this.metaDataProvider.GetMetaInfo(dto.ClassKind.ToString()); var classlessDto = new ClasslessDTO(); - foreach (var property in jsonObject.Properties()) + + foreach (var property in jsonObject.EnumerateObject()) { var propertyName = Utils.CapitalizeFirstLetter(property.Name); classlessDto.Add(propertyName, metainfo.GetValue(propertyName, dto)); @@ -200,4 +148,4 @@ private ClasslessDTO GenerateClasslessDto(JObject jsonObject, Dto.Thing dto) return classlessDto; } } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs new file mode 100644 index 000000000..5dfa81c43 --- /dev/null +++ b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs @@ -0,0 +1,111 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.JsonConverter +{ + using System; + using System.Linq; + + using CDP4Common.DTO; + using CDP4Common.MetaInfo; + + /// + /// The purpose of the is to implement extra business logic for hand-coded serialization to + /// decide to include or exclude classes from the serialization process + /// + public class ThingConverterExtensions + { + /// + /// Asserts whether an object shall be serialized or not + /// + /// + /// the for which the serialization is to be asserted + /// + /// + /// The used to provide meta data + /// + /// + /// The data model version to be used to determine whether a class shall be serialized or not + /// + /// + /// returns true when the object shall be serialzed, false if not + /// + public bool AssertSerialization(object value, IMetaDataProvider metaDataProvider, Version version) + { + if (value is PersonPermission personPermission) + { + var classVersion = new Version(metaDataProvider.GetClassVersion(personPermission.ObjectClass.ToString())); + + if (classVersion > version) + { + return false; + } + } + + if (value is ParticipantPermission participantPermission) + { + var classVersion = new Version(metaDataProvider.GetClassVersion(participantPermission.ObjectClass.ToString())); + + if (classVersion > version) + { + return false; + } + } + + return true; + } + + /// + /// Checks the 's property for compatibility + /// + /// + /// the for which the serialization is to be asserted + /// + /// + /// The used to provide meta data + /// + /// + /// The data model version to be used to determine whether a class shall be serialized or not + /// + public void CheckCategoryPermissibleClasses(object value, IMetaDataProvider metaDataProvider, Version version) + { + if (value is Category category) + { + var permissibleClasses = category.PermissibleClass.ToList(); + + foreach (var permissibleClass in permissibleClasses) + { + var permissibleClassVersion = new Version(metaDataProvider.GetClassVersion(permissibleClass.ToString())); + + if (permissibleClassVersion <= version) + { + continue; + } + + category.PermissibleClass.Remove(permissibleClass); + } + } + } + } +} diff --git a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs index eaad81729..bc8bb911b 100644 --- a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs @@ -1,47 +1,43 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.JsonConverter { using System; - using System.Collections.Generic; - using System.Linq; + using System.Text.Json; + using System.Text.Json.Serialization; using CDP4Common.DTO; - using CDP4Common.Extensions; using CDP4Common.MetaInfo; using CDP4Common.Polyfills; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using NLog; /// - /// The that is responsible for (De)serialization on a + /// The that is responsible for (De)serialization on a /// - public class ThingSerializer : JsonConverter + public class ThingSerializer : JsonConverter { /// /// The NLog logger @@ -54,10 +50,20 @@ public class ThingSerializer : JsonConverter private readonly Version dataModelVersion; /// - /// The used to determine whether a class is to be serialized or not + /// Override default null handling + /// + public override bool HandleNull => true; + + /// + /// The used to determine whether a class is to be serialized or not /// private readonly ThingConverterExtensions thingConverterExtensions; + /// + /// Gets or sets the meta info provider. + /// + private IMetaDataProvider MetaInfoProvider { get; set; } + /// /// Initializes a new instance of the class. /// @@ -75,21 +81,6 @@ public ThingSerializer(IMetaDataProvider metaInfoProvider, Version dataModelVers this.thingConverterExtensions = new ThingConverterExtensions(); } - /// - /// Gets a value indicating whether this converter supports JSON read. - /// - public override bool CanRead => true; - - /// - /// Gets a value indicating whether this converter supports JSON write. - /// - public override bool CanWrite => true; - - /// - /// Gets or sets the meta info provider. - /// - private IMetaDataProvider MetaInfoProvider { get; set; } - /// /// Override of the can convert type check. /// @@ -105,18 +96,33 @@ public override bool CanConvert(Type objectType) } /// - /// Write JSON. + /// Tries to deserialize a JSON into a /// - /// - /// The JSON writer. - /// - /// - /// The value object. - /// - /// - /// The JSON serializer. - /// - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + /// the + /// the to convert + /// the options of the serializer + /// the + public override Thing Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + // load object from stream + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) + { + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new NullReferenceException("The data object in the JSON array could not be cast to a JsonElement type."); + } + + var newThing = jsonElement?.ToDto(); + + return newThing; + } + + /// + /// Write a JSON + /// + /// the + /// the to serialize + /// the options of the serializer + public override void Write(Utf8JsonWriter writer, Thing value, JsonSerializerOptions options) { var typeName = value.GetType().Name; var classVersion = new Version(this.MetaInfoProvider.GetClassVersion(typeName)); @@ -134,62 +140,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s } this.thingConverterExtensions.CheckCategoryPermissibleClasses(value, this.MetaInfoProvider, this.dataModelVersion); - - var jsonObject = ((Thing)value).ToJsonObject(); - - // remove versioned properties - var nonSerializableProperties = new List(); - - foreach (var kvp in jsonObject) - { - var propertyVersion = new Version(this.MetaInfoProvider.GetPropertyVersion(typeName, Helper.Utils.CapitalizeFirstLetter(kvp.Key))); - - if (propertyVersion > this.dataModelVersion) - { - nonSerializableProperties.Add(kvp.Key); - } - } - - foreach (var nonSerializableProperty in nonSerializableProperties) - { - jsonObject.Remove(nonSerializableProperty); - } - - jsonObject.WriteTo(writer); - } - - /// - /// Override of the Read JSON method. - /// - /// - /// The JSON reader. - /// - /// - /// The type information of the object. - /// - /// - /// The existing object value. - /// - /// - /// The JSON serializer. - /// - /// - /// A deserialized instance. - /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - // load object from stream - var jsonObject = JObject.Load(reader); - - if (jsonObject == null) - { - Logger.Error("The data object in the JSON array could not be cast to a JObject type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JObject type."); - } - - var newThing = jsonObject.ToDto(); - - return newThing; + value.SerializeThing(writer, this.dataModelVersion); } } } diff --git a/CDP4JsonSerializer/Properties/AssemblyInfo.cs b/CDP4JsonSerializer/Properties/AssemblyInfo.cs index fd03f6cc9..c9db8d273 100644 --- a/CDP4JsonSerializer/Properties/AssemblyInfo.cs +++ b/CDP4JsonSerializer/Properties/AssemblyInfo.cs @@ -26,5 +26,6 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("CDP4JsonSerializer.Tests")] -[assembly: InternalsVisibleTo("CDP4JsonSerializer.NetCore.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Cdp4JsonSerializer")] +[assembly: InternalsVisibleTo("Cdp4JsonSerializer.Tests")] +[assembly: InternalsVisibleTo("Cdp4JsonSerializer.NetCore.Tests")] \ No newline at end of file diff --git a/CDP4JsonSerializer/SerializerOptions.cs b/CDP4JsonSerializer/SerializerOptions.cs new file mode 100644 index 000000000..ac115c6b1 --- /dev/null +++ b/CDP4JsonSerializer/SerializerOptions.cs @@ -0,0 +1,88 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer +{ + using System.Text.Json; + + /// + /// Static class with the options used in the serializer + /// + public class SerializerOptions + { + /// + /// Backing field for the property + /// + private static JsonSerializerOptions options; + + /// + /// Object to lock the options + /// + private static readonly object Lock = new(); + + /// + /// Creates a new instance of type + /// + private SerializerOptions() + { + } + + /// + /// Gets the instance that it's been used of this + /// + public static JsonSerializerOptions Options + { + get + { + if (options == null) + { + lock (Lock) + { + if (options == null) + { + options = new JsonSerializerOptions() + { + WriteIndented = false, + Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + PropertyNameCaseInsensitive = true, + NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString + }; + } + } + } + + return options; + } + } + + /// + /// Copies the and returns a new instance + /// + /// the new instance + public static JsonSerializerOptions Copy() + { + return new JsonSerializerOptions(Options); + } + } +} diff --git a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj index ed51f420b..1895939a8 100644 --- a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj +++ b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj @@ -11,7 +11,8 @@ - + + diff --git a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs index bb7920766..26b2eac6e 100644 --- a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -49,7 +49,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -92,7 +93,7 @@ public void Setup() this.siteDirectory = new SiteDirectory(Guid.Parse("f13de6f8-b03a-46e7-a492-53b2f260f294"), this.session.Assembler.Cache, this.uri); var lazySiteDirectory = new Lazy(() => this.siteDirectory); lazySiteDirectory.Value.Cache.TryAdd(new CacheKey(lazySiteDirectory.Value.Iid, null), lazySiteDirectory); - + this.jsonSerializerOptions = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, @@ -183,7 +184,7 @@ public void Verify_That_When_constructed_with_null_httpclient_throws_exception() HttpClient httpClient = null; Assert.Throws(() => new CdpServicesDal(httpClient)); } - + [Test] [Category("WebServicesDependent")] public async Task VerifThatAClosedDalCannotBeClosedAgain() @@ -254,17 +255,18 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed() Assert.Throws(() => this.dal.Close()); } - [Test] + [TestCase(true)] + [TestCase(false)] [Category("WebServicesDependent")] - public async Task VerifyThatReadReturnsCorrectDTO() + public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported) { - this.dal = new CdpServicesDal(); + this.dal = new CdpServicesDal(isMessagePackSupported); var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList(); Assert.NotNull(returned); Assert.IsNotEmpty(returned); - var sd = returned.First(); + var sd = returned.First(x => x.ClassKind == ClassKind.SiteDirectory); var attributes = new QueryAttributes(); var readResult = await dal.Read(sd, this.cancelationTokenSource.Token, attributes); @@ -326,6 +328,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() IsSynonym = false, LanguageCode = "en", }; + testDtoOriginal.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoOriginal.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -335,6 +338,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() IsSynonym = true, LanguageCode = "en", }; + testDtoModified.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoModified.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -343,6 +347,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() Content = "somecontent", LanguageCode = "en", }; + testDtoOriginal2.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoOriginal2.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -351,6 +356,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() Content = "somecontent2", LanguageCode = "en", }; + testDtoModified2.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoModified2.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -477,10 +483,11 @@ public async Task AssemblerSynchronizePerformanceTest() await assembler.Clear(); } }, Throws.Nothing); - + var synchronizeMeanElapsedTime = elapsedTimes.Average(); var maxElapsedTime = elapsedTimes.Max(); var minElapsedTime = elapsedTimes.Min(); + // 204.64 | 181 | 458 ms // refactor: 31.61 | 26 | 283 } @@ -497,7 +504,7 @@ public async Task VerifyThatFileCanBeUploaded() var files = new List { filepath }; var contentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - var uri = new Uri("https://cdp4services-test.cdp4.org"); + var uri = new Uri("https://cdp4services-test.cdp4.org"); this.credentials = new Credentials("admin", "pass", uri); var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token); @@ -621,25 +628,24 @@ public async Task Verify_that_opens_returns_expected_result() public async Task Verify_that_open_with_proxy_returns_expected_result() { var proxySettings = new ProxySettings(new Uri("http://tinyproxy:8888")); - + var uri = new Uri("https://cdp4services-test.cdp4.org"); this.credentials = new Credentials("admin", "pass", uri, proxySettings); var dal = new CdpServicesDal(); var result = await dal.Open(this.credentials, new CancellationToken()); - + Assert.NotNull(result); } - + [Test] [Category("WebServicesDependent")] public async Task Verify_that_multiple_read_requests_can_be_made_in_parallel() { var uri = new Uri("https://cdp4services-test.cdp4.org"); var credentials = new Credentials("admin", "pass", uri); - + var dal = new CdpServicesDal(); - var result = await dal.Open(credentials, new CancellationToken()); @@ -699,7 +705,7 @@ public async Task VerifyReadCometTask() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var cometTaskId = Guid.NewGuid(); var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}/{cometTaskId}"); @@ -748,7 +754,7 @@ public async Task VerifyReadCometTasks() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}"); var notFoundHttpResponse = new HttpResponseMessage() @@ -764,7 +770,7 @@ public async Task VerifyReadCometTasks() var cometTasks = new List() { - new () + new() { Id = Guid.NewGuid(), Actor = Guid.NewGuid(), @@ -830,7 +836,7 @@ public async Task VerifyWriteLongRunningTask() newCometTaskResponse.Content = new StringContent(JsonSerializer.Serialize(cometTask, this.jsonSerializerOptions)); SetHttpHeader(newCometTaskResponse, "application/json"); - var longRunningTaskResult = await this.dal.Write(operationContainer,1); + var longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -848,7 +854,7 @@ public async Task VerifyWriteLongRunningTask() thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); - longRunningTaskResult = await this.dal.Write(operationContainer,1); + longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { diff --git a/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs index 3d4f62827..4a5a30208 100644 --- a/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs index dff2ca099..924ad8832 100644 --- a/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs index c573a6a4f..02d0ce7e4 100644 --- a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -35,34 +35,35 @@ namespace CDP4ServicesDal.Tests using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer; - using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer; + using CDP4ServicesDal.Tests.Helper; - - using Newtonsoft.Json; - + using NUnit.Framework; - + using File = System.IO.File; - + [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0)); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { var test = this.serializer.Deserialize(stream); @@ -147,25 +148,21 @@ public override void ConstructFromOperation(Operation operation) /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_copy")] public override List Copy { get; set; } } } diff --git a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs index 8da697ecc..1fe4b0b24 100644 --- a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -38,6 +38,7 @@ namespace CDP4ServicesDal.Tests using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; @@ -47,9 +48,10 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; - using Newtonsoft.Json; + using CDP4JsonSerializer; using NUnit.Framework; @@ -76,12 +78,13 @@ public class CdpServicesDalTestFixture private SiteReferenceDataLibrary siteReferenceDataLibrary; private ModelReferenceDataLibrary modelReferenceDataLibrary; private CDPMessageBus messageBus; + private Cdp4JsonSerializer jsonSerializer; [SetUp] public void Setup() { this.cancelationTokenSource = new CancellationTokenSource(); - + this.credentials = new Credentials("admin", "pass", this.uri); this.dal = new CdpServicesDal(); this.messageBus = new CDPMessageBus(); @@ -91,7 +94,8 @@ public void Setup() this.siteDirectory = new SiteDirectory(Guid.Parse("f13de6f8-b03a-46e7-a492-53b2f260f294"), this.session.Assembler.Cache, this.uri); var lazySiteDirectory = new Lazy(() => this.siteDirectory); lazySiteDirectory.Value.Cache.TryAdd(new CacheKey(lazySiteDirectory.Value.Iid, null), lazySiteDirectory); - + var metaDataProvider = new MetaDataProvider(); + this.jsonSerializer = new Cdp4JsonSerializer(metaDataProvider, metaDataProvider.GetMaxSupportedModelVersion()); this.PopulateSiteDirectory(); } @@ -228,17 +232,18 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed() Assert.Throws(() => this.dal.Close()); } - [Test] + [TestCase(true)] + [TestCase(false)] [Category("WebServicesDependent")] - public async Task VerifyThatReadReturnsCorrectDTO() + public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported) { - this.dal = new CdpServicesDal(); + this.dal = new CdpServicesDal(isMessagePackSupported); var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList(); Assert.NotNull(returned); Assert.IsNotEmpty(returned); - var sd = returned.First(); + var sd = returned.First(x => x.ClassKind == ClassKind.SiteDirectory); var attributes = new QueryAttributes(); var readResult = await this.dal.Read(sd, this.cancelationTokenSource.Token, attributes); @@ -687,7 +692,7 @@ public async Task Verify_that_person_can_be_Posted() Assert.NotNull(resultPerson); } - [Test] + [Test] public async Task VerifyReadCometTask() { var mockHttp = new MockHttpMessageHandler(); @@ -696,7 +701,7 @@ public async Task VerifyReadCometTask() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var cometTaskId = Guid.NewGuid(); var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}/{cometTaskId}"); @@ -722,7 +727,7 @@ public async Task VerifyReadCometTask() StatusKind = StatusKind.SUCCEEDED }; - foundHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + foundHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(foundHttpResponse, "application/json"); var readCometTask = await this.dal.ReadCometTask(cometTaskId, CancellationToken.None); @@ -730,7 +735,7 @@ public async Task VerifyReadCometTask() var messagePackHttpResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackHttpResponse); - messagePackHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + messagePackHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(messagePackHttpResponse, "application/msgpack"); Assert.That(() => this.dal.ReadCometTask(cometTaskId, CancellationToken.None), Throws.Exception.TypeOf()); @@ -745,7 +750,7 @@ public async Task VerifyReadCometTasks() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}"); var notFoundHttpResponse = new HttpResponseMessage() @@ -772,7 +777,7 @@ public async Task VerifyReadCometTasks() } }; - foundHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTasks)); + foundHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTasks)); SetHttpHeader(foundHttpResponse, "application/json"); var readCometTasks = await this.dal.ReadCometTasks(CancellationToken.None); @@ -780,7 +785,7 @@ public async Task VerifyReadCometTasks() var messagePackHttpResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackHttpResponse); - messagePackHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTasks)); + messagePackHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTasks)); SetHttpHeader(messagePackHttpResponse, "application/msgpack"); Assert.That(() => this.dal.ReadCometTasks(CancellationToken.None), Throws.Exception.TypeOf()); @@ -826,10 +831,10 @@ public async Task VerifyWriteLongRunningTask() var newCometTaskResponse = new HttpResponseMessage(); requestHandler.Respond(_ => newCometTaskResponse); - newCometTaskResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + newCometTaskResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(newCometTaskResponse, "application/json"); - var longRunningTaskResult = await this.dal.Write(operationContainer,1); + var longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -847,7 +852,7 @@ public async Task VerifyWriteLongRunningTask() thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); - longRunningTaskResult = await this.dal.Write(operationContainer,1); + longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -859,7 +864,7 @@ public async Task VerifyWriteLongRunningTask() var messagePackResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackResponse); - messagePackResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + messagePackResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(messagePackResponse, "application/msgpack"); Assert.That(() => this.dal.Write(operationContainer, 1), Throws.Exception.TypeOf()); } diff --git a/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs b/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs index c523778d0..4efa0f6e6 100644 --- a/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs b/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs index fc2a7f0fc..fcf4893de 100644 --- a/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs +++ b/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// ------------------------------------------------------------------------------------------------------------------------------- +// // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs index 3aa18fdb7..02d0ce7e4 100644 --- a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -35,14 +35,14 @@ namespace CDP4ServicesDal.Tests using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer; - using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer; + using CDP4ServicesDal.Tests.Helper; - - using Newtonsoft.Json; - + using NUnit.Framework; using File = System.IO.File; @@ -50,19 +50,20 @@ namespace CDP4ServicesDal.Tests [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0)); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { var test = this.serializer.Deserialize(stream); @@ -88,7 +89,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( originalDomainFileStore.AddContainer(ClassKind.Iteration, iterationIid); originalDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); - var modifiedDomainFileStore = originalDomainFileStore.DeepClone(); + var modifiedDomainFileStore = originalDomainFileStore.DeepClone(); modifiedDomainFileStore.File.Add(fileIid); var file = new CDP4Common.DTO.File(fileIid, 0); @@ -101,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() {K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -122,7 +123,8 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var postOperation = new CdpPostOperation(new MetaDataProvider(), null); - foreach (var operation in operationContainer.Operations) { + foreach (var operation in operationContainer.Operations) + { postOperation.ConstructFromOperation(operation); } @@ -146,25 +148,21 @@ public override void ConstructFromOperation(Operation operation) /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_copy")] public override List Copy { get; set; } } } diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 0977ea912..7ae08223d 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -27,6 +27,7 @@ + @@ -39,13 +40,9 @@ - - - - - + diff --git a/CDP4ServicesDal/CdpPostOperation.cs b/CDP4ServicesDal/CdpPostOperation.cs index 1e29338a6..afe1adf8c 100644 --- a/CDP4ServicesDal/CdpPostOperation.cs +++ b/CDP4ServicesDal/CdpPostOperation.cs @@ -1,28 +1,26 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { @@ -30,16 +28,19 @@ namespace CDP4ServicesDal using System.Collections; using System.Collections.Generic; using System.Linq; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.EngineeringModelData; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; - using Newtonsoft.Json; + + using CDP4DalCommon.Protocol.Operations; /// /// The CDP POST operation @@ -81,25 +82,21 @@ internal CdpPostOperation(IMetaDataProvider metaDataProvider, ISession session) /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to copy. /// - [JsonProperty("_copy")] public override List Copy { get; set; } /// @@ -154,6 +151,7 @@ private void ResolveUpdate(Operation operation) foreach (var key in original.Keys) { var originalIenumerable = original[key] as IEnumerable; + if (originalIenumerable != null && originalIenumerable.GetType().IsGenericType) { var modifiedIenumerable = (IEnumerable)modifiedFull[key]; @@ -177,6 +175,7 @@ private void ResolveUpdate(Operation operation) List modifiedProperty; var genericTypeArgument = original[key].GetType().GenericTypeArguments[0]; + if (genericTypeArgument == typeof(Guid) || genericTypeArgument == typeof(ClassKind) || genericTypeArgument == typeof(VcardTelephoneNumberKind)) { originalProperty = originalIenumerable.Cast().ToList(); @@ -221,6 +220,7 @@ private void ResolveUpdate(Operation operation) } var possibleDeletions = originalProperty.Except(modifiedProperty).ToList(); + if (possibleDeletions.Count > 0) { // this part will be added to the delete @@ -275,6 +275,7 @@ private void ResolveUpdate(Operation operation) if (listsToAdd.Count > 0) { var updateDto = modified; + foreach (var kvp in listsToAdd) { updateDto.Add(kvp.Key, kvp.Value); @@ -311,18 +312,20 @@ private void ResolveCopy(Operation operation) var source = new CopySource { - Thing = new CopyReference {Iid = operation.OriginalThing.Iid, ClassKind = operation.OriginalThing.ClassKind}, - TopContainer = new CopyReference {Iid = sourcepoco.TopContainer.Iid, ClassKind = sourcepoco.TopContainer.ClassKind}, + Thing = new CopyReference { Iid = operation.OriginalThing.Iid, ClassKind = operation.OriginalThing.ClassKind }, + TopContainer = new CopyReference { Iid = sourcepoco.TopContainer.Iid, ClassKind = sourcepoco.TopContainer.ClassKind }, IterationId = sourceIteration?.Iid }; var poco = operation.ModifiedThing.QuerySourceThing(); + if (poco.Container == null) { throw new InvalidOperationException("The container cannot be null."); } var targetIteration = poco.GetContainerOfType(); + var target = new CopyTarget { Container = new CopyReference { Iid = poco.Container.Iid, ClassKind = poco.Container.ClassKind }, diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index 05aec3413..9a2a3cd45 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -27,7 +27,6 @@ namespace CDP4ServicesDal #if NETFRAMEWORK using System.ComponentModel.Composition; #endif - using System; using System.Collections.Generic; using System.Diagnostics; @@ -44,7 +43,6 @@ namespace CDP4ServicesDal using CDP4Common.CommonData; using CDP4Common.DTO; using CDP4Common.Extensions; - using CDP4DalCommon.Tasks; using CDP4Dal; using CDP4Dal.Composition; @@ -53,7 +51,10 @@ namespace CDP4ServicesDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4JsonSerializer; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; + + using CDP4DalJsonSerializer; using CDP4MessagePackSerializer; @@ -88,13 +89,21 @@ public class CdpServicesDal : Dal /// private HttpClient httpClient; + /// + /// Asserts that the MessagePack deserialization should be used or not + /// + private readonly bool isMessagePackSupported; + /// /// Initializes a new instance of the class. /// - public CdpServicesDal() + /// Asserts that the MessagePack deserialization should be used or not. Supported by default + public CdpServicesDal(bool isMessagePackSupported = true) { - this.Cdp4JsonSerializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); this.MessagePackSerializer = new MessagePackSerializer(); + + this.isMessagePackSupported = isMessagePackSupported; } /// @@ -103,7 +112,8 @@ public CdpServicesDal() /// /// The (injected) /// - public CdpServicesDal(HttpClient httpClient) : this() + /// Asserts that the MessagePack deserialization should be used or not. Supported by default + public CdpServicesDal(HttpClient httpClient, bool isMessagePackSupported = true) : this(isMessagePackSupported) { if (httpClient == null) { @@ -114,9 +124,9 @@ public CdpServicesDal(HttpClient httpClient) : this() } /// - /// Gets the + /// Gets the /// - public Cdp4JsonSerializer Cdp4JsonSerializer { get; private set; } + public Cdp4DalJsonSerializer Cdp4JsonSerializer { get; private set; } /// /// Gets the @@ -323,7 +333,7 @@ public override async Task Write(OperationContainer opera case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Long running task not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -716,7 +726,7 @@ public override async Task ReadCometTask(Guid id, CancellationToken c case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Read CometTask by id not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -777,7 +787,7 @@ public override async Task> ReadCometTasks(CancellationTo case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Read all CometTask not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -1051,7 +1061,12 @@ private HttpClient CreateHttpClient(Credentials credentials, HttpClient injected result.BaseAddress = credentials.Uri; result.DefaultRequestHeaders.Accept.Clear(); result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack")); + + if (this.isMessagePackSupported) + { + result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack")); + } + result.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($"{credentials.UserName}:{credentials.Password}"))); result.DefaultRequestHeaders.Add(Headers.AcceptCdpVersion, Headers.AcceptCdpVersionValue); result.DefaultRequestHeaders.Add("User-Agent", "CDP4 (ECSS-E-TM-10-25 Annex C.2) CDPServicesDal"); @@ -1364,8 +1379,8 @@ private LongRunningTaskResult ExtractResultFromStream(Stream stream) var firstChar = (char)reader.Peek(); stream.Position = 0; - return firstChar == '[' - ? new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)) + return firstChar == '[' + ? new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)) : new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)); } } diff --git a/CDP4ServicesDal/CopyOperationHandler.cs b/CDP4ServicesDal/CopyOperationHandler.cs index c54e612f2..4596d0fb3 100644 --- a/CDP4ServicesDal/CopyOperationHandler.cs +++ b/CDP4ServicesDal/CopyOperationHandler.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { @@ -31,12 +31,13 @@ namespace CDP4ServicesDal using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; - using CDP4Common.Helpers; using CDP4Dal; using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Poco = CDP4Common.CommonData.Thing; /// @@ -55,7 +56,7 @@ internal class CopyOperationHandler private readonly ISession session; /// - /// A that map the original to the copied version + /// A that map the original to the copied version /// private Dictionary copyThingMap; @@ -95,6 +96,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) var operationsToAdd = new List(); var copyOperationCount = operationContainer.Operations.Count(x => x.OperationKind.IsCopyOperation()); + if (copyOperationCount > 1) { // TODO: support this if needed @@ -102,6 +104,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) } var copyOperation = operationContainer.Operations.SingleOrDefault(x => x.OperationKind.IsCopyOperation()); + if (copyOperation == null) { return; @@ -156,6 +159,7 @@ private void ComputeOperations(Operation copyOperation) // Add all contained objects this.copyableIds.AddRange(copyPermissionResult.CopyableThings.Select(c => c.Iid).ToList()); + if (this.copyableIds.Contains(originalPoco.Iid)) { var updatedIteration = copyPoco.GetContainerOfType(); @@ -164,6 +168,7 @@ private void ComputeOperations(Operation copyOperation) // modify the references to point to the copy thing this.ModifyReferences(); + if (copyOperation.OperationKind.IsCopyChangeOwnerOperation()) { this.ChangeOwner(updatedIteration); @@ -209,6 +214,7 @@ private void CreatePocoCopy(Poco poco, Iteration targetIteration) foreach (var containerList in poco.ContainerLists) { var updatedContainerList = new List(); + foreach (Poco containedPoco in containerList) { if (!this.copyableIds.Contains(containedPoco.Iid)) @@ -311,6 +317,7 @@ private void ModifyReferences(ElementUsage usage) private void ModifyReferences(Parameter parameter) { parameter.StateDependence = null; + if (parameter.Group == null) { return; @@ -319,6 +326,7 @@ private void ModifyReferences(Parameter parameter) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(parameter.Group, out groupCopy); + parameter.Group = this.copyThingMap.TryGetValue(parameter.Group, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -338,6 +346,7 @@ private void ModifyReferences(ParameterGroup group) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy); + group.ContainingGroup = this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -361,12 +370,14 @@ private void ModifyReferences(ParameterOverride parameterOverride) private void ChangeOwner(Iteration iteration) { var activeDomain = this.session.OpenIterations.Single(x => x.Key.Iid == iteration.Iid).Value.Item1; + if (activeDomain == null) { throw new InvalidOperationException("The active domain is null. The copy operation cannot be performed."); } var ownedThings = this.copyThingMap.Values.OfType().ToList(); + foreach (var ownedThing in ownedThings) { // the owner of a subscription shall not be set to the active one @@ -379,4 +390,4 @@ private void ChangeOwner(Iteration iteration) } } } -} \ No newline at end of file +} diff --git a/CDP4ServicesDal/OperationModifier.cs b/CDP4ServicesDal/OperationModifier.cs index e47afbed0..c1c91970d 100644 --- a/CDP4ServicesDal/OperationModifier.cs +++ b/CDP4ServicesDal/OperationModifier.cs @@ -1,44 +1,42 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { - using System; using System.Collections.Generic; using System.Linq; - using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; - using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; - using ElementUsage = CDP4Common.DTO.ElementUsage; - using ParameterOverride = CDP4Common.DTO.ParameterOverride; - using ParameterSubscription = CDP4Common.DTO.ParameterSubscription; using PossibleFiniteStateList = CDP4Common.DTO.PossibleFiniteStateList; - + /// /// The purpose of the is to perform operations that /// are not performed directly by the server @@ -73,6 +71,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) if (operation.OperationKind == OperationKind.Update) { var possibleStateList = operation.ModifiedThing as PossibleFiniteStateList; + if (possibleStateList != null) { operationsToAdd.AddRange(this.ModifyActualStateKindOnDefaultPossibleStateUpdate(possibleStateList)); @@ -95,6 +94,7 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate { var operations = new List(); var defaultStateId = possibleFiniteStateList.DefaultState; + if (!defaultStateId.HasValue) { return operations; @@ -102,14 +102,15 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate // gets the actualList that uses the updated possible list var actualLists = this.session.Assembler.Cache.Select(x => x.Value) - .Select(x => x.Value) - .OfType() - .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) - .ToList(); + .Select(x => x.Value) + .OfType() + .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) + .ToList(); foreach (var actualFiniteStateList in actualLists) { var possibleLists = actualFiniteStateList.PossibleFiniteStateList.Where(x => x.Iid != possibleFiniteStateList.Iid).ToList(); + if (possibleLists.Any(x => x.DefaultState == null)) { // one of the possible list has no default state @@ -141,4 +142,4 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate return operations; } } -} \ No newline at end of file +} diff --git a/CDP4ServicesDal/ValueSetOperationCreator.cs b/CDP4ServicesDal/ValueSetOperationCreator.cs index da614ddbb..06beb83a4 100644 --- a/CDP4ServicesDal/ValueSetOperationCreator.cs +++ b/CDP4ServicesDal/ValueSetOperationCreator.cs @@ -1,38 +1,41 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using Dto = CDP4Common.DTO; /// @@ -44,7 +47,7 @@ internal class ValueSetOperationCreator /// The associated /// private readonly ISession session; - + /// /// Initializes a new instance of the class /// @@ -70,6 +73,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume var dtolist = dtos.ToList(); var topContainer = dtolist.SingleOrDefault(x => x is Dto.TopContainer); + if (topContainer == null) { throw new InvalidOperationException("No Top container were found in the returned list of dtos."); @@ -78,9 +82,10 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // Gets the parameter base which value set shall be updated var copyParameterBases = dtolist.OfType().ToList(); var copyParameterBasesIds = copyParameterBases.Select(p => p.Iid).ToList(); + var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || - dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || - dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); + dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || + dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); this.ComputeRoutes(valuesets, dtolist); var valueSetsClones = valuesets.Select(dto => dto.DeepClone()).ToList(); @@ -98,6 +103,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // value sets to update var copyValueSets = valueSetsClones.Where(x => copyDto.ValueSets.Contains(x.Iid)).ToList(); var defaultValueSet = this.GetDefaultValueSet(originalParameter); + if (defaultValueSet == null) { continue; @@ -107,6 +113,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume } var operationContainer = new OperationContainer(context, topContainer.RevisionNumber); + foreach (var valueSetsClone in valueSetsClones) { var valuesetToUpdate = valuesets.Single(x => x.Iid == valueSetsClone.Iid); @@ -203,4 +210,4 @@ private void SetValueSetValues(Dto.ParameterSubscriptionValueSet valueSet, Param valueSet.ValueSwitch = originalValueSet.ValueSwitch; } } -} \ No newline at end of file +} diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index 81eca8dea..31b1156fd 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 diff --git a/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs b/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs index 93581f856..7504aba46 100644 --- a/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs +++ b/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2023 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Antoine Théate, Nathanael Smiechowski -// -// This file is part of COMET-SDK Community Edition -// -// The CDP4-COMET-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,13 +27,12 @@ namespace CDP4ServicesMessaging.Serializers.Json using System; using System.Diagnostics; using System.IO; - + using System.Text.Json; + using CDP4Common.MetaInfo; using CDP4JsonSerializer; - using Newtonsoft.Json; - using NLog; /// @@ -58,7 +57,7 @@ public Cdp4MessageSerializer() /// /// The public Cdp4MessageSerializer(IMetaDataProvider metaInfoProvider) : base(metaInfoProvider, metaInfoProvider.GetMaxSupportedModelVersion()) - { + { } /// @@ -70,27 +69,22 @@ public Cdp4MessageSerializer(IMetaDataProvider metaInfoProvider) : base(metaInfo public ReadOnlyMemory Serialize(T message) { var sw = Stopwatch.StartNew(); - var serializer = this.CreateJsonSerializer(); // Use a MemoryStream to store the serialized data using var memoryStream = new MemoryStream(); - Logger.Trace("initializing JsonTextWriter"); - using var jsonWriter = new JsonTextWriter(new StreamWriter(memoryStream)); - Logger.Trace("Serialize to JsonTextWriter"); - serializer.Serialize(jsonWriter, message); - jsonWriter.Flush(); + JsonSerializer.Serialize(memoryStream, message, this.JsonSerializerOptions); // Get the ReadOnlyMemory from the MemoryStream var serializedMessage = new ReadOnlyMemory(memoryStream.ToArray()); sw.Stop(); Logger.Debug("SerializeThingsChangedMessage finished in {0} [ms]", sw.ElapsedMilliseconds); - + return serializedMessage; } - + /// /// Deserializes a message of type from the specified . /// diff --git a/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs b/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs index 075e19824..037c9cb96 100644 --- a/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs b/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs index 66b06dbd7..d8376f1f3 100644 --- a/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4WspDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs index 61510f108..5c1bd2b3f 100644 --- a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,40 +1,38 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests.Operations { using System; using System.Collections; - using System.Collections.Generic; using System.Linq; + using CDP4Common.DTO; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4Dal.Operations; - using CDP4WspDal; + + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -101,7 +99,7 @@ public void VerifyThatExceptionIsThrownWhenModifiedThingIsNotProvided() { var simpleUnit = new SimpleUnit(Guid.NewGuid(), 1); var operation = new Operation(simpleUnit, null, OperationKind.Delete); - Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)) ; + Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)); } [Test] diff --git a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs index 2a0bd0d22..1a41f72a7 100644 --- a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs @@ -1,61 +1,70 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { using System; using System.Collections.Generic; using System.IO; + using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.Dto; + using CDP4Common.DTO; using CDP4Common.MetaInfo; - using CDP4JsonSerializer; + using CDP4Common.Types; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer; + using CDP4WspDal.Tests.Helper; - using Newtonsoft.Json; + using NUnit.Framework; - using CDP4Common.DTO; - using CDP4Common.CommonData; - using CDP4Common.Types; + using File = System.IO.File; + using Thing = CDP4Common.DTO.Thing; [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), true); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { Assert.DoesNotThrow(() => this.serializer.Deserialize(stream)); @@ -93,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -101,7 +110,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); var context = $"/EngineeringModel/{engineeringModelIid}/iteration/{iterationIid}"; - var operationContainer = new OperationContainer(context, null); + var operationContainer = new OperationContainer(context); var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update); operationContainer.AddOperation(updateCommonFileStoreOperation); @@ -131,34 +140,30 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] - public override List Create { get; set; } + public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_copy")] public override List Copy { get; set; } + + public override void ConstructFromOperation(Operation operation) + { + throw new NotImplementedException(); + } } } } diff --git a/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs b/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs index 19f356f88..71c71bc46 100644 --- a/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -45,6 +45,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.DAL.ECSS1025AnnexC; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// diff --git a/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs b/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs index f5b4c39e9..3050dcd75 100644 --- a/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.Tests/OperationModifierTestFixture.cs b/CDP4WspDal.Tests/OperationModifierTestFixture.cs index 355d6e127..d8376f1f3 100644 --- a/CDP4WspDal.Tests/OperationModifierTestFixture.cs +++ b/CDP4WspDal.Tests/OperationModifierTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// ------------------------------------------------------------------------------------------------------------------------------- +// // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4WspDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs index 61510f108..5c1bd2b3f 100644 --- a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,40 +1,38 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests.Operations { using System; using System.Collections; - using System.Collections.Generic; using System.Linq; + using CDP4Common.DTO; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4Dal.Operations; - using CDP4WspDal; + + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -101,7 +99,7 @@ public void VerifyThatExceptionIsThrownWhenModifiedThingIsNotProvided() { var simpleUnit = new SimpleUnit(Guid.NewGuid(), 1); var operation = new Operation(simpleUnit, null, OperationKind.Delete); - Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)) ; + Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)); } [Test] diff --git a/CDP4WspDal.Tests/PostOperationTestFixture.cs b/CDP4WspDal.Tests/PostOperationTestFixture.cs index 64a169578..1a41f72a7 100644 --- a/CDP4WspDal.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/PostOperationTestFixture.cs @@ -1,61 +1,70 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { using System; using System.Collections.Generic; using System.IO; + using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.DTO; using CDP4Common.MetaInfo; - using CDP4JsonSerializer; + using CDP4Common.Types; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4DalJsonSerializer; + using CDP4WspDal.Tests.Helper; - using Newtonsoft.Json; + using NUnit.Framework; - using CDP4Common.Types; + using File = System.IO.File; - using CDP4Common.CommonData; + using Thing = CDP4Common.DTO.Thing; [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), true); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { Assert.DoesNotThrow(() => this.serializer.Deserialize(stream)); @@ -93,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -101,7 +110,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); var context = $"/EngineeringModel/{engineeringModelIid}/iteration/{iterationIid}"; - var operationContainer = new OperationContainer(context, null); + var operationContainer = new OperationContainer(context); var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update); operationContainer.AddOperation(updateCommonFileStoreOperation); @@ -128,36 +137,33 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( Assert.AreEqual(expected, streamReader.ReadToEnd()); } } + private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] - public override List Create { get; set; } + public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_copy")] public override List Copy { get; set; } + + public override void ConstructFromOperation(Operation operation) + { + throw new NotImplementedException(); + } } } } diff --git a/CDP4WspDal.Tests/WSPDalTestFixture.cs b/CDP4WspDal.Tests/WSPDalTestFixture.cs index 025de3d3c..a643d9751 100644 --- a/CDP4WspDal.Tests/WSPDalTestFixture.cs +++ b/CDP4WspDal.Tests/WSPDalTestFixture.cs @@ -1,8 +1,8 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 RHEA System S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -45,6 +45,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.DAL.ECSS1025AnnexC; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index ecb36ab64..62ffa7c86 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -41,7 +41,7 @@ - + diff --git a/CDP4WspDal/CopyOperationHandler.cs b/CDP4WspDal/CopyOperationHandler.cs index c9190b976..2b66111c2 100644 --- a/CDP4WspDal/CopyOperationHandler.cs +++ b/CDP4WspDal/CopyOperationHandler.cs @@ -1,28 +1,26 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { @@ -30,11 +28,16 @@ namespace CDP4WspDal using System.Collections.Generic; using System.Linq; using System.Reflection; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; using CDP4Dal.Permission; + + using CDP4DalCommon.Protocol.Operations; + using Poco = CDP4Common.CommonData.Thing; /// @@ -53,7 +56,7 @@ internal class CopyOperationHandler private readonly ISession session; /// - /// A that map the original to the copied version + /// A that map the original to the copied version /// private Dictionary copyThingMap; @@ -82,7 +85,7 @@ public CopyOperationHandler(ISession session) public IReadOnlyDictionary CopyThingMap { get { return this.copyThingMap; } - } + } /// /// Modify the if it contains copy @@ -93,6 +96,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) var operationsToAdd = new List(); var copyOperationCount = operationContainer.Operations.Count(x => x.OperationKind.IsCopyOperation()); + if (copyOperationCount > 1) { // TODO: support this if needed @@ -100,6 +104,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) } var copyOperation = operationContainer.Operations.SingleOrDefault(x => x.OperationKind.IsCopyOperation()); + if (copyOperation == null) { return; @@ -140,7 +145,7 @@ private void ComputeOperations(Operation copyOperation) var originalDto = copyOperation.OriginalThing; var originalPoco = originalDto.QuerySourceThing(); - + if (copyPoco.TopContainer.ClassKind != ClassKind.EngineeringModel) { throw new InvalidOperationException("The copy operation on WSP is only implemented for things contained by EngineeringModel."); @@ -154,6 +159,7 @@ private void ComputeOperations(Operation copyOperation) // Add all contained objects this.copyableIds.AddRange(copyPermissionResult.CopyableThings.Select(c => c.Iid).ToList()); + if (this.copyableIds.Contains(originalPoco.Iid)) { var updatedIteration = copyPoco.GetContainerOfType(); @@ -162,6 +168,7 @@ private void ComputeOperations(Operation copyOperation) // modify the references to point to the copy thing this.ModifyReferences(); + if (copyOperation.OperationKind.IsCopyChangeOwnerOperation()) { this.ChangeOwner(updatedIteration); @@ -207,6 +214,7 @@ private void CreatePocoCopy(Poco poco, Iteration targetIteration) foreach (var containerList in poco.ContainerLists) { var updatedContainerList = new List(); + foreach (Poco containedPoco in containerList) { if (!this.copyableIds.Contains(containedPoco.Iid)) @@ -265,6 +273,7 @@ private void CreateOperations() } #region Modify References + /// /// Modify the references for a and all its contained elements /// @@ -310,6 +319,7 @@ private void ModifyReferences(ElementUsage usage) private void ModifyReferences(Parameter parameter) { parameter.StateDependence = null; + if (parameter.Group == null) { return; @@ -318,6 +328,7 @@ private void ModifyReferences(Parameter parameter) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(parameter.Group, out groupCopy); + parameter.Group = this.copyThingMap.TryGetValue(parameter.Group, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -337,6 +348,7 @@ private void ModifyReferences(ParameterGroup group) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy); + group.ContainingGroup = this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -352,6 +364,7 @@ private void ModifyReferences(ParameterOverride parameterOverride) var copy = (Parameter)this.copyThingMap[parameterOverride.Parameter]; parameterOverride.Parameter = copy; } + #endregion /// @@ -361,12 +374,14 @@ private void ModifyReferences(ParameterOverride parameterOverride) private void ChangeOwner(Iteration iteration) { var activeDomain = this.session.OpenIterations.Single(x => x.Key.Iid == iteration.Iid).Value.Item1; + if (activeDomain == null) { throw new InvalidOperationException("The active domain is null. The copy operation cannot be performed."); } var ownedThings = this.copyThingMap.Values.OfType().ToList(); + foreach (var ownedThing in ownedThings) { // the owner of a subscription shall not be set to the active one @@ -379,4 +394,4 @@ private void ChangeOwner(Iteration iteration) } } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/OperationModifier.cs b/CDP4WspDal/OperationModifier.cs index 03629343b..52cea9c70 100644 --- a/CDP4WspDal/OperationModifier.cs +++ b/CDP4WspDal/OperationModifier.cs @@ -1,38 +1,42 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; using ElementUsage = CDP4Common.DTO.ElementUsage; using ParameterOverride = CDP4Common.DTO.ParameterOverride; @@ -72,6 +76,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) if (operation.OperationKind == OperationKind.Create) { var parameterOverride = operation.ModifiedThing as ParameterOverride; + if (parameterOverride != null) { operationsToAdd.AddRange(this.AddParameterSubscriptionCreateOperation(operationContainer, parameterOverride)); @@ -80,6 +85,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) else if (operation.OperationKind == OperationKind.Update) { var possibleStateList = operation.ModifiedThing as PossibleFiniteStateList; + if (possibleStateList != null) { operationsToAdd.AddRange(this.ModifyActualStateKindOnDefaultPossibleStateUpdate(possibleStateList)); @@ -90,7 +96,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) foreach (var operation in operationsToAdd) { operationContainer.AddOperation(operation); - } + } } /// @@ -104,12 +110,14 @@ private IEnumerable AddParameterSubscriptionCreateOperation(Operation var parameterId = parameterOverride.Parameter; Lazy lazyParameter; var operations = new List(); + if (!this.session.Assembler.Cache.TryGetValue(new CacheKey(parameterId, parameterOverride.IterationContainerId), out lazyParameter)) { return operations; } - + var parameter = (Parameter)lazyParameter.Value; + foreach (var subscription in parameter.ParameterSubscription.Where(x => x.Owner.Iid != parameterOverride.Owner)) { var parameterSubscription = new ParameterSubscription @@ -123,13 +131,14 @@ private IEnumerable AddParameterSubscriptionCreateOperation(Operation operationContainer.Operations.Select(x => x.ModifiedThing) .OfType() .SingleOrDefault(x => x.ParameterOverride.Contains(parameterOverride.Iid)); - + if (elementUsageContainer == null) { continue; } Lazy lazyElementUsageContainer; + if (!this.session.Assembler.Cache.TryGetValue(new CacheKey(elementUsageContainer.Iid, elementUsageContainer.IterationContainerId), out lazyElementUsageContainer)) { continue; @@ -166,6 +175,7 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate { var operations = new List(); var defaultStateId = possibleFiniteStateList.DefaultState; + if (!defaultStateId.HasValue) { return operations; @@ -173,14 +183,15 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate // gets the actualList that uses the updated possible list var actualLists = this.session.Assembler.Cache.Select(x => x.Value) - .Select(x => x.Value) - .OfType() - .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) - .ToList(); + .Select(x => x.Value) + .OfType() + .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) + .ToList(); foreach (var actualFiniteStateList in actualLists) { var possibleLists = actualFiniteStateList.PossibleFiniteStateList.Where(x => x.Iid != possibleFiniteStateList.Iid).ToList(); + if (possibleLists.Any(x => x.DefaultState == null)) { // one of the possible list has no default state @@ -212,4 +223,4 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate return operations; } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/ValueSetOperationCreator.cs b/CDP4WspDal/ValueSetOperationCreator.cs index a4e49ccd3..9aa9f59db 100644 --- a/CDP4WspDal/ValueSetOperationCreator.cs +++ b/CDP4WspDal/ValueSetOperationCreator.cs @@ -1,38 +1,41 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using Dto = CDP4Common.DTO; /// @@ -44,7 +47,7 @@ internal class ValueSetOperationCreator /// The associated /// private readonly ISession session; - + /// /// Initializes a new instance of the class /// @@ -70,6 +73,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume var dtolist = dtos.ToList(); var topContainer = dtolist.SingleOrDefault(x => x is Dto.TopContainer); + if (topContainer == null) { throw new InvalidOperationException("No Top container were found in the returned list of dtos."); @@ -78,9 +82,10 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // Gets the parameter base which value set shall be updated var copyParameterBases = dtolist.OfType().ToList(); var copyParameterBasesIds = copyParameterBases.Select(p => p.Iid).ToList(); - var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || - dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || - dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); + + var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || + dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || + dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); this.ComputeRoutes(valuesets, dtolist); var valueSetsClones = valuesets.Select(dto => dto.DeepClone()).ToList(); @@ -98,6 +103,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // value sets to update var copyValueSets = valueSetsClones.Where(x => copyDto.ValueSets.Contains(x.Iid)).ToList(); var defaultValueSet = this.GetDefaultValueSet(originalParameter); + if (defaultValueSet == null) { continue; @@ -105,8 +111,9 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume this.SetValueSetValues(copyValueSets, defaultValueSet); } - + var operationContainer = new OperationContainer(context, topContainer.RevisionNumber); + foreach (var valueSetsClone in valueSetsClones) { var valuesetToUpdate = valuesets.Single(x => x.Iid == valueSetsClone.Iid); @@ -203,4 +210,4 @@ private void SetValueSetValues(Dto.ParameterSubscriptionValueSet valueSet, Param valueSet.ValueSwitch = originalValueSet.ValueSwitch; } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/WSPDal.cs b/CDP4WspDal/WSPDal.cs index 8c80db5c1..fe475eff7 100644 --- a/CDP4WspDal/WSPDal.cs +++ b/CDP4WspDal/WSPDal.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2021 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,7 +27,6 @@ namespace CDP4WspDal #if NETFRAMEWORK using System.ComponentModel.Composition; #endif - using System; using System.Collections.Generic; using System.Diagnostics; @@ -50,10 +49,11 @@ namespace CDP4WspDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; + + using CDP4DalJsonSerializer; - using CDP4JsonSerializer; - using NLog; using EngineeringModelSetup = CDP4Common.SiteDirectoryData.EngineeringModelSetup; @@ -83,13 +83,13 @@ public class WspDal : Dal /// public WspDal() { - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, true); } /// - /// Gets or sets the + /// Gets or sets the /// - public Cdp4JsonSerializer Serializer { get; private set; } + public Cdp4DalJsonSerializer Serializer { get; private set; } /// /// Gets the value indicating whether this is read only @@ -140,18 +140,19 @@ public override async Task> Write(OperationContainer operatio modifier.ModifyOperationContainer(operationContainer); var invalidOperationKind = operationContainer.Operations.Any(operation => operation.OperationKind == OperationKind.Move || OperationKindExtensions.IsCopyOperation(operation.OperationKind)); + if (invalidOperationKind) { throw new InvalidOperationKindException("The WSP DAL does not support Copy or Move operations"); } - + var result = new List(); if (files != null && files.Any()) { this.OperationContainerFileVerification(operationContainer, files); } - + var attribute = new QueryAttributes { RevisionNumber = operationContainer.TopContainerRevisionNumber @@ -180,12 +181,13 @@ public override async Task> Write(OperationContainer operatio Logger.Error(msg); throw new DalWriteException(msg); } - + using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { result.AddRange(this.Serializer.Deserialize(resultStream)); Guid iterationId; + if (this.TryExtractIterationIdfromUri(httpResponseMessage.RequestMessage.RequestUri, out iterationId)) { this.SetIterationContainer(result, iterationId); @@ -204,6 +206,7 @@ public override async Task> Write(OperationContainer operatio foreach (var valueSetDto in valueSetResult) { var index = result.FindIndex(x => x.Iid == valueSetDto.Iid); + if (index >= 0) { result[index] = valueSetDto; @@ -282,6 +285,7 @@ public override async Task> Read(CDP4Common.DTO.Iteration ite // Get the RequiredRdl to load var siteDirectory = this.Session.Assembler.RetrieveSiteDirectory(); var iterationSetup = siteDirectory.Model.SelectMany(mod => mod.IterationSetup).SingleOrDefault(it => it.IterationIid == iteration.Iid); + if (iterationSetup == null) { throw new InvalidOperationException("The Iteration to open does not have any associated IterationSetup."); @@ -401,12 +405,13 @@ public override async Task> Read(T thing, CancellationToke Logger.Error(msg); throw new DalReadException(msg); } - + using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { var returned = this.Serializer.Deserialize(resultStream); Guid iterationId; + if (this.TryExtractIterationIdfromUri(httpResponseMessage.RequestMessage.RequestUri, out iterationId)) { this.SetIterationContainer(returned, iterationId); @@ -419,7 +424,7 @@ public override async Task> Read(T thing, CancellationToke } } } - + /// /// Reads the identified by the provided /// @@ -529,9 +534,9 @@ public override async Task> Open(Credentials credentials, Can var openToken = CDP4Common.Helpers.TokenGenerator.GenerateRandomToken(); this.httpClient = this.CreateHttpClient(credentials); - + var watch = Stopwatch.StartNew(); - + var uriBuilder = this.GetUriBuilder(credentials.Uri, ref resourcePath); Logger.Debug("Resource Path {0}: {1}", openToken, resourcePath); @@ -543,7 +548,7 @@ public override async Task> Open(Credentials credentials, Can { Logger.Info("The ECSS-E-TM-10-25A Annex C Services responded in {0} [ms] to Open {1}", requestsw.ElapsedMilliseconds, openToken); requestsw.Stop(); - + if (httpResponseMessage.StatusCode != HttpStatusCode.OK) { var msg = $"The data-source replied with code {httpResponseMessage.StatusCode}: {httpResponseMessage.ReasonPhrase}"; @@ -553,7 +558,7 @@ public override async Task> Open(Credentials credentials, Can watch.Stop(); Logger.Info("WSP DAL Open {0} completed in {1} [ms]", openToken, watch.ElapsedMilliseconds); - + watch = Stopwatch.StartNew(); using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) @@ -564,6 +569,7 @@ public override async Task> Open(Credentials credentials, Can Logger.Info("JSON Deserializer completed in {0} [ms]", watch.ElapsedMilliseconds); var returnedPerson = returned.OfType().SingleOrDefault(x => x.ShortName == credentials.UserName); + if (returnedPerson == null) { throw new InvalidOperationException("User not found."); @@ -709,6 +715,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op { outputStream.CopyTo(memoryStream); memoryStream.Position = 0; + using (var streamReader = new StreamReader(memoryStream)) { var postBody = streamReader.ReadToEnd(); @@ -763,6 +770,7 @@ public override bool IsValidUri(string uri) try { var validUriAssertion = new Uri(uri); + if (!(validUriAssertion.Scheme == Uri.UriSchemeHttp || validUriAssertion.Scheme == Uri.UriSchemeHttps)) { return false; @@ -814,6 +822,6 @@ private IQueryAttributes GetIUriQueryAttribute(bool includeReferenceData = false Extent = ExtentQueryAttribute.deep, IncludeAllContainers = true }; - } + } } } diff --git a/CDP4WspDal/WSPPostOperation.cs b/CDP4WspDal/WSPPostOperation.cs index 5c403befe..8888b2b27 100644 --- a/CDP4WspDal/WSPPostOperation.cs +++ b/CDP4WspDal/WSPPostOperation.cs @@ -1,28 +1,26 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 RHEA System S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { @@ -30,15 +28,16 @@ namespace CDP4WspDal using System.Collections; using System.Collections.Generic; using System.Linq; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using CDP4Dal.Operations; - using Newtonsoft.Json; - using DomainOfExpertise = CDP4Common.DTO.DomainOfExpertise; + + using CDP4DalCommon.Protocol.Operations; + using Thing = CDP4Common.DTO.Thing; /// @@ -63,25 +62,21 @@ public WspPostOperation(IMetaDataProvider metaDataProvider) /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public override List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public override List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public override List Update { get; set; } /// /// Gets or sets the collection of DTOs to copy. /// - [JsonIgnore] public override List Copy { get; set; } /// @@ -139,6 +134,7 @@ private void ResolveUpdate(Operation operation) foreach (var key in original.Keys) { var originalIenumerable = original[key] as IEnumerable; + if (originalIenumerable != null && originalIenumerable.GetType().IsGenericType) { var modifiedIenumerable = (IEnumerable)modifiedFull[key]; @@ -162,6 +158,7 @@ private void ResolveUpdate(Operation operation) List modifiedProperty; var genericTypeArgument = original[key].GetType().GenericTypeArguments[0]; + if (genericTypeArgument == typeof(Guid) || genericTypeArgument == typeof(ClassKind) || genericTypeArgument == typeof(VcardTelephoneNumberKind)) { originalProperty = originalIenumerable.Cast().ToList(); @@ -206,6 +203,7 @@ private void ResolveUpdate(Operation operation) } var possibleDeletions = originalProperty.Except(modifiedProperty).ToList(); + if (possibleDeletions.Count > 0) { // this part will be added to the delete @@ -236,7 +234,7 @@ private void ResolveUpdate(Operation operation) { if (original[key].Equals(modifiedFull[key])) { - modified.Remove(key); + modified.Remove(key); } } } @@ -260,6 +258,7 @@ private void ResolveUpdate(Operation operation) if (listsToAdd.Count > 0) { var updateDto = modified; + foreach (var kvp in listsToAdd) { updateDto.Add(kvp.Key, kvp.Value); @@ -271,6 +270,6 @@ private void ResolveUpdate(Operation operation) { this.Update.Add(modified); } - } + } } } From b6ad0cbcfbb262d5d1624f4cf6d3c0cea2248b9d Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 15:58:16 +0100 Subject: [PATCH 02/34] Fix SQ issues --- CDP4Dal.NetCore.Tests/SessionTestFixture.cs | 17 +--- .../Cdp4DalJsonSerializer.cs | 12 +-- .../PostOperationJsonConverter.cs | 4 +- CDP4JsonSerializer/Cdp4JsonSerializer.cs | 84 ++++++++++--------- .../JsonConverter/ClasslessDtoSerializer.cs | 5 +- .../JsonConverter/ThingSerializer.cs | 11 +-- 6 files changed, 65 insertions(+), 68 deletions(-) diff --git a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs index ee986c74a..30a16a392 100644 --- a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs @@ -818,20 +818,11 @@ private void AssignActivePerson() [DalExport("test dal", "test dal description", "1.1.0", DalType.Web)] internal class TestDal : IDal { - public Version SupportedVersion - { - get { return new Version(1, 0, 0); } - } + public static Version SupportedVersion => new (1, 0, 0); - public Version DalVersion - { - get { return new Version("1.1.0"); } - } - - public IMetaDataProvider MetaDataProvider - { - get { return new MetaDataProvider(); } - } + public Version DalVersion => new(1, 1, 0); + + public IMetaDataProvider MetaDataProvider => new MetaDataProvider(); /// /// Gets or sets the that uses this diff --git a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs index 5b9e6f660..cb927415d 100644 --- a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs +++ b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs @@ -55,10 +55,9 @@ public class Cdp4DalJsonSerializer : Cdp4JsonSerializer /// The supported version of the data-model /// /// Asserts that the have to be ignored - public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty = false) + public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty = false) { this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; - this.Initialize(metaInfoProvider, supportedVersion); } @@ -72,14 +71,11 @@ public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty = false) } /// - /// Initialize this instance with the required and supported + /// Initialize the property /// - /// The - /// The supported - public override void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) + public override void InitializeJsonSerializerOptions() { - base.Initialize(metaInfoProvider, supportedVersion); - + base.InitializeJsonSerializerOptions(); this.JsonSerializerOptions.Converters.Add(new PostOperationJsonConverter(this.ignorePostOperationCopyProperty)); } } diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs index 90b70787c..4da5579bd 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -75,7 +75,7 @@ public override bool CanConvert(Type typeToConvert) return typeof(PostOperation).QueryIsAssignableFrom(typeToConvert); } - /// Reads and converts the JSON to type . + /// Reads and converts the JSON to type . /// The reader. /// The type to convert. /// An object that specifies serialization options to use. @@ -96,7 +96,7 @@ public override PostOperation Read(ref Utf8JsonReader reader, Type typeToConvert throw new InvalidDataException($"The request Type {typeToConvert.Name} is not a PostOperation"); } - jsonElement?.DeserializePostOperation(postOperation, options); + jsonElement.Value.DeserializePostOperation(postOperation, options); return postOperation; } diff --git a/CDP4JsonSerializer/Cdp4JsonSerializer.cs b/CDP4JsonSerializer/Cdp4JsonSerializer.cs index 2d72690bf..0294ba5a4 100644 --- a/CDP4JsonSerializer/Cdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4JsonSerializer.cs @@ -90,15 +90,11 @@ public Cdp4JsonSerializer() /// /// The /// The supported - public virtual void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) + public void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) { this.MetaInfoProvider = metaInfoProvider; this.RequestDataModelVersion = supportedVersion; - - this.JsonSerializerOptions = SerializerOptions.Copy(); - this.JsonSerializerOptions.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - this.JsonSerializerOptions.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false)); + this.InitializeJsonSerializerOptions(); } /// @@ -216,6 +212,44 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten return jsonString; } + + /// + /// Serialize an object into a string + /// + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + public string SerializeToString(object toSerialize) + { + if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) + { + throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); + } + + Logger.Trace("initializing MemoryStream"); + + using var stream = new MemoryStream(); + + this.SerializeToStream(toSerialize, stream); + + Logger.Trace("rewind MemoryStream"); + stream.Position = 0; + + Logger.Trace("initializing StreamReader"); + using var reader = new StreamReader(stream); + + var sw = new Stopwatch(); + sw.Start(); + var jsonString = reader.ReadToEnd(); + sw.Stop(); + Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); + + return jsonString; + } + /// /// Convenience method that deserializes the passed in JSON content stream /// @@ -257,40 +291,14 @@ public T Deserialize(Stream contentStream) } /// - /// Serialize an object into a string + /// Initialize the property /// - /// The object to serialize - /// The serialized string - /// - /// If the or - /// has not been initialized - /// - public string SerializeToString(object toSerialize) + public virtual void InitializeJsonSerializerOptions() { - if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) - { - throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); - } - - Logger.Trace("initializing MemoryStream"); - - using var stream = new MemoryStream(); - - this.SerializeToStream(toSerialize, stream); - - Logger.Trace("rewind MemoryStream"); - stream.Position = 0; - - Logger.Trace("initializing StreamReader"); - using var reader = new StreamReader(stream); - - var sw = new Stopwatch(); - sw.Start(); - var jsonString = reader.ReadToEnd(); - sw.Stop(); - Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); - - return jsonString; + this.JsonSerializerOptions = SerializerOptions.Copy(); + this.JsonSerializerOptions.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false)); } } } diff --git a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs index 969d8bd09..a93f10eb8 100644 --- a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs @@ -25,6 +25,7 @@ namespace CDP4JsonSerializer.JsonConverter { using System; + using System.IO; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; @@ -98,10 +99,10 @@ public override ClasslessDTO Read(ref Utf8JsonReader reader, Type typeToConvert, if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) { Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JsonElement type."); } - var dto = jsonElement?.ToDto(); + var dto = jsonElement.Value.ToDto(); var classlessDto = this.GenerateClasslessDto(jsonElement.Value, dto); return classlessDto; diff --git a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs index bc8bb911b..44658341e 100644 --- a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs @@ -25,6 +25,7 @@ namespace CDP4JsonSerializer.JsonConverter { using System; + using System.IO; using System.Text.Json; using System.Text.Json.Serialization; @@ -84,15 +85,15 @@ public ThingSerializer(IMetaDataProvider metaInfoProvider, Version dataModelVers /// /// Override of the can convert type check. /// - /// + /// /// The object type. /// /// /// true if this converter is to be used. /// - public override bool CanConvert(Type objectType) + public override bool CanConvert(Type typeToConvert) { - return typeof(Thing).QueryIsAssignableFrom(objectType); + return typeof(Thing).QueryIsAssignableFrom(typeToConvert); } /// @@ -108,10 +109,10 @@ public override Thing Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) { Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JsonElement type."); } - var newThing = jsonElement?.ToDto(); + var newThing = jsonElement.Value.ToDto(); return newThing; } From 3493e78d777eb3fb2a5681cded9207922d77f433 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 16:08:28 +0100 Subject: [PATCH 03/34] Update README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index a21cdbe69..41c10e1bc 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ The CDP4-COMET Software Development Kit is an C# SDK that that is compliant with - CDP4Reporting - CDP4Dal - CDP4DalCommon + - CDP4DalJsonSerializer - CDP4JsonFileDal - CDP4ServicesDal - CDP4WspDal @@ -32,6 +33,7 @@ CDP4MessagePackSerializer | [![NuGet Badge](https://buildstats.info/nuget/CDP4Me CDP4Reporting | [![NuGet Badge](https://buildstats.info/nuget/CDP4Reporting-CE)](https://buildstats.info/nuget/CDP4Reporting-CE) CDP4Dal | [![NuGet Badge](https://buildstats.info/nuget/CDP4Dal-CE)](https://buildstats.info/nuget/CDP4Dal-CE) CDP4DalCommon | [![NuGet Badge](https://buildstats.info/nuget/CDP4DalCommon-CE)](https://buildstats.info/nuget/CDP4DalCommon-CE) +CDP4DalJsonSerializer | [![NuGet Badge](https://buildstats.info/nuget/CDP4DalJsonSerializer-CE)](https://buildstats.info/nuget/CDP4DalJsonSerializer-CE) CDP4JsonFileDal | [![NuGet Badge](https://buildstats.info/nuget/CDP4JsonFileDal-CE)](https://buildstats.info/nuget/CDP4JsonFileDal-CE) CDP4ServicesDal | [![NuGet Badge](https://buildstats.info/nuget/CDP4ServicesDal-CE)](https://buildstats.info/nuget/CDP4ServicesDal-CE) CDP4WspDal | [![NuGet Badge](https://buildstats.info/nuget/CDP4WspDal-CE)](https://buildstats.info/nuget/CDP4WspDal-CE) @@ -91,6 +93,10 @@ The CDP4Dal library is a library that provides the basis to implement ECSS-E-TM- The CDP4DalCommon library provides common classes to support the ECSS-E-TM-10-25 and CDP4-COMET protocol. +## CDP4DalJsonSerializer + +The CDP4DalJsonSerializer library provides JsonSerializer converter for common classes contained in CDP4DalCommon library. + ## CDP4JsonFileDal The CDP4JsonFileDal library is a C# library that provides an implementation of ECSS-E-TM-10-25A Annex C.3, the JSON Exchange File Format. This file format is a ZIP archive in which a number of files are stored that each contain one or more ECSS-E-TM-10-25 objects that are serialized in the form of a JSON array of JSON objects. The CDP4JsonFileDal library can be used to read from such a ZIP archive, and to create such a ZIP archive. The ZIP archive is typically used to exchange complete models between organizations. From 843b096018d9530a833ac914db947b0be879fee8 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 16:20:10 +0100 Subject: [PATCH 04/34] Fix SQ issue --- CDP4JsonSerializer/ICdp4JsonSerializer.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/CDP4JsonSerializer/ICdp4JsonSerializer.cs b/CDP4JsonSerializer/ICdp4JsonSerializer.cs index 79d3bb656..5e4f1747e 100644 --- a/CDP4JsonSerializer/ICdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/ICdp4JsonSerializer.cs @@ -86,6 +86,17 @@ public interface ICdp4JsonSerializer /// A value indicating whether the contained shall be processed /// The JSON string string SerializeToString(CDP4Common.CommonData.Thing source, bool isExtentDeep); + + /// + /// Serialize an object into a string + /// + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + string SerializeToString(object toSerialize); /// /// Convenience method that deserializes the passed in JSON content stream @@ -97,16 +108,5 @@ public interface ICdp4JsonSerializer /// The the deserialized collection of . /// IEnumerable Deserialize(Stream contentStream); - - /// - /// Serialize an object into a string - /// - /// The object to serialize - /// The serialized string - /// - /// If the or - /// has not been initialized - /// - string SerializeToString(object toSerialize); } } From 721771b8f32ca12e5d74b5318e182204a4c087de Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 16:51:25 +0100 Subject: [PATCH 05/34] space indentation and encoding in all csproj file + versionbump script --- CDP4Dal/CDP4Dal.csproj | 6 +- CDP4DalCommon/CDP4DalCommon.csproj | 86 +++++++-------- .../CDP4DalJsonSerializer.csproj | 88 +++++++-------- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 2 +- .../CDP4MessagePackSerializer.csproj | 92 ++++++++-------- .../CDP4RequirementsVerification.csproj | 94 ++++++++-------- CDP4Rules/CDP4Rules.csproj | 2 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 4 +- .../CDP4ServicesMessaging.Tests.csproj | 14 +-- .../CDP4ServicesMessaging.csproj | 100 +++++++++--------- CDP4WspDal/CDP4WspDal.csproj | 2 +- versionBump.sh | 20 ++++ 12 files changed, 265 insertions(+), 245 deletions(-) create mode 100644 versionBump.sh diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index 806174b7d..39f6e6968 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -26,7 +26,7 @@ - + @@ -44,10 +44,10 @@ - + - \ No newline at end of file + diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj index f8d4e19e4..6492b4827 100644 --- a/CDP4DalCommon/CDP4DalCommon.csproj +++ b/CDP4DalCommon/CDP4DalCommon.csproj @@ -1,43 +1,43 @@ - - - - net47;net471;net472;net48;netstandard2.0;netstandard2.1 - RHEA System S.A. - latest - CDP4DalCommon Community Edition - 26.6.0 - CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal - Copyright © RHEA System S.A. - Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime - CDP4DalCommon-CE - true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition - true - cdp4-icon.png - true - true - snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 - LGPL-3.0-only - - [BUMP] To CDP4Common 26.6.0 - - README.md - true - latest - - - - \ - true - - - \ - true - - - - - - + + + + net47;net471;net472;net48;netstandard2.0;netstandard2.1 + RHEA System S.A. + latest + CDP4DalCommon Community Edition + 26.6.0 + CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime + CDP4DalCommon-CE + true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + true + latest + + + + \ + true + + + \ + true + + + + + + diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj index 765eb528d..0d369da52 100644 --- a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj +++ b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj @@ -1,44 +1,44 @@ - - - - net47;net471;net472;net48;netstandard2.0;netstandard2.1 - RHEA System S.A. - latest - CDP4DalJsonSerializer Community Edition - 26.6.0 - JsonSerializer for the CDP4DalCommon types - Copyright © RHEA System S.A. - Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime - CDP4DalJsonSerializer-CE - true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition - true - cdp4-icon.png - true - true - snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 - LGPL-3.0-only - - [BUMP] To CDP4Common 26.6.0 - - README.md - true - latest - - - - \ - true - - - \ - true - - - - - - - + + + + net47;net471;net472;net48;netstandard2.0;netstandard2.1 + RHEA System S.A. + latest + CDP4DalJsonSerializer Community Edition + 26.6.0 + JsonSerializer for the CDP4DalCommon types + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime + CDP4DalJsonSerializer-CE + true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + true + latest + + + + \ + true + + + \ + true + + + + + + + diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 14c3d6b0f..7aa1aaf3d 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -21,7 +21,7 @@ [BUMP] To CDP4Common 26.6.0 - 11.0 + 11.0 diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index 4e7fb4f6d..141e91958 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -1,46 +1,46 @@ - - - - net47;net471;net472;net48;netstandard2.0;netstandard2.1 - RHEA System S.A. - CDP4MessagePackSerializer Community Edition - 26.6.0 - CDP4 MessagePack Serialization Library - Copyright © RHEA System S.A. - Sam, Alex, Alexander, Nathanael, Antoine, Omar - CDP4MessagePackSerializer-CE - true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition - true - cdp4-icon.png - true - true - snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 MessagePack - LGPL-3.0-only - - [BUMP] To CDP4Common 26.6.0 - - README.md - - - - - - - - - - - - - - - - - - - - - + + + + net47;net471;net472;net48;netstandard2.0;netstandard2.1 + RHEA System S.A. + CDP4MessagePackSerializer Community Edition + 26.6.0 + CDP4 MessagePack Serialization Library + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Nathanael, Antoine, Omar + CDP4MessagePackSerializer-CE + true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 MessagePack + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + + + + + + + + + + + + + + + + + + + + + diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj index 9ba6c95d7..4f30819bb 100644 --- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj +++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj @@ -1,47 +1,47 @@ - - - - net47;net471;net472;net48;netstandard2.0;netstandard2.1 - RHEA System S.A. - CDP4RequirementsVerification Community Edition - 26.6.0 - CDP4 Class Library that provides requirement verification - Copyright © RHEA System S.A. - Sam, Alex, Alexander, Yevhen, Nathanael - CDP4RequirementsVerification-CE - true - http://sdk.cdp4.org - true - cdp4-icon.png - true - true - snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 - LGPL-3.0-only - - [BUMP] To CDP4Common 26.6.0 - - README.md - - - - - - - - bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - - - - - - - - - - - + + + + net47;net471;net472;net48;netstandard2.0;netstandard2.1 + RHEA System S.A. + CDP4RequirementsVerification Community Edition + 26.6.0 + CDP4 Class Library that provides requirement verification + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Yevhen, Nathanael + CDP4RequirementsVerification-CE + true + http://sdk.cdp4.org + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + + + + + + + + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + + + + + + + + + diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj index 579d715b0..2afbe9233 100644 --- a/CDP4Rules/CDP4Rules.csproj +++ b/CDP4Rules/CDP4Rules.csproj @@ -26,7 +26,7 @@ - + diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 7ae08223d..451b04abe 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -26,8 +26,8 @@ - - + + diff --git a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj index 4d19bf081..b49795cf2 100644 --- a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj +++ b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj @@ -11,20 +11,20 @@ - + - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - runtime; build; native; contentfiles; analyzers; buildtransitive - all + runtime; build; native; contentfiles; analyzers; buildtransitive + all - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index 31b1156fd..5c08f200b 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -1,50 +1,50 @@ - - - - netstandard2.0 - RHEA System S.A. - CDP4Common Community Edition - 26.6.0 - CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication - Copyright © RHEA System S.A. - Sam, Alex, Alexander, Nathanael, Antoine - CDP4ServicesMessaging-CE - true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition - true - cdp4-icon.png - true - true - snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 - LGPL-3.0-only - - [BUMP] To CDP4Common 26.6.0 - - README.md - latest - - - - - \ - true - - - \ - true - - - - - - - - - - - - - - + + + + netstandard2.0 + RHEA System S.A. + CDP4Common Community Edition + 26.6.0 + CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication + Copyright © RHEA System S.A. + Sam, Alex, Alexander, Nathanael, Antoine + CDP4ServicesMessaging-CE + true + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + true + cdp4-icon.png + true + true + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + CDP COMET ECSS-E-TM-10-25 + LGPL-3.0-only + + [BUMP] To CDP4Common 26.6.0 + + README.md + latest + + + + + \ + true + + + \ + true + + + + + + + + + + + + + + diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index 62ffa7c86..320a42a74 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -26,7 +26,7 @@ - + diff --git a/versionBump.sh b/versionBump.sh new file mode 100644 index 000000000..853534081 --- /dev/null +++ b/versionBump.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +rootFolder=$(pwd) + +newVersionPrefix=$1 + +# Get all .csproj files recursively within the root folder and discard tests project +projectFiles=$(find "$rootFolder" -type f -name '*.csproj' | grep -v 'Tests.csproj') + +for file in $projectFiles; do + sed "s|\(\)[^<]*\(<\/VersionPrefix>\)|\1$newVersionPrefix\2|g" "$file" > "$file.tmp" + mv "$file.tmp" "$file" +done + +echo "VersionPrefix updated to $newVersionPrefix in all .csproj files." From f1aee5c678d36f5bbe9c964a29f15cc16c689da1 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Thu, 21 Mar 2024 17:09:52 +0100 Subject: [PATCH 06/34] Missing method on ICDP4JsonSerializer interface --- CDP4JsonSerializer/ICdp4JsonSerializer.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CDP4JsonSerializer/ICdp4JsonSerializer.cs b/CDP4JsonSerializer/ICdp4JsonSerializer.cs index 5e4f1747e..452fecc12 100644 --- a/CDP4JsonSerializer/ICdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/ICdp4JsonSerializer.cs @@ -108,5 +108,19 @@ public interface ICdp4JsonSerializer /// The the deserialized collection of . /// IEnumerable Deserialize(Stream contentStream); + + /// + /// Convenience method that deserializes the passed in JSON content stream + /// + /// + /// The type info for which deserialization will be performed + /// + /// + /// The content Stream. + /// + /// + /// The the deserialized instance of the specified Type + /// + T Deserialize(Stream contentStream); } } From bb9e07a5717c510eeb564a5e894f1769dd118516 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 10:09:41 +0100 Subject: [PATCH 07/34] Added Deserialize from string --- CDP4JsonSerializer/Cdp4JsonSerializer.cs | 27 ++++++++++++++++++++++- CDP4JsonSerializer/ICdp4JsonSerializer.cs | 14 ++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CDP4JsonSerializer/Cdp4JsonSerializer.cs b/CDP4JsonSerializer/Cdp4JsonSerializer.cs index 0294ba5a4..7449cf694 100644 --- a/CDP4JsonSerializer/Cdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4JsonSerializer.cs @@ -211,7 +211,6 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten return jsonString; } - /// /// Serialize an object into a string @@ -290,6 +289,32 @@ public T Deserialize(Stream contentStream) return data; } + /// + /// Convenience method that deserializes the passed in JSON content stream + /// + /// + /// The type info for which deserialization will be performed + /// + /// + /// The content string. + /// + /// + /// The the deserialized instance of the specified Type + /// + public T Deserialize(string contentString) + { + if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) + { + throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); + } + + var sw = new Stopwatch(); + sw.Start(); + var data = JsonSerializer.Deserialize(contentString, this.JsonSerializerOptions); + Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); + return data; + } + /// /// Initialize the property /// diff --git a/CDP4JsonSerializer/ICdp4JsonSerializer.cs b/CDP4JsonSerializer/ICdp4JsonSerializer.cs index 452fecc12..6a2aa7799 100644 --- a/CDP4JsonSerializer/ICdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/ICdp4JsonSerializer.cs @@ -122,5 +122,19 @@ public interface ICdp4JsonSerializer /// The the deserialized instance of the specified Type /// T Deserialize(Stream contentStream); + + /// + /// Convenience method that deserializes the passed in JSON content stream + /// + /// + /// The type info for which deserialization will be performed + /// + /// + /// The content string. + /// + /// + /// The the deserialized instance of the specified Type + /// + T Deserialize(string contentString); } } From 585d6fb049c5e95f3a8b9f3fe353ed2cc3eb93e7 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 10:12:12 +0100 Subject: [PATCH 08/34] added snupkg --- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 7aa1aaf3d..8477f5c22 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -1,4 +1,4 @@ - + net47;net471;net472;net48;netstandard2.0;netstandard2.1 @@ -15,7 +15,8 @@ cdp4-icon.png true true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + snupkg + https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git CDP COMET ECSS-E-TM-10-25 JSON LGPL-3.0-only From 160c20804d9a653113bf2864df6ae42b98ad096d Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 11:28:26 +0100 Subject: [PATCH 09/34] PostOperation is concrete class now --- .../Operations/PostOperationTestFixture.cs | 12 --------- .../Operations/PostOperationTestFixture.cs | 12 --------- .../Protocol/Operations/PostOperation.cs | 26 +++++++++++-------- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 2 +- .../CDP4ServicesDal.NetCore.Tests.csproj | 1 - .../PostOperationTestFixture.cs | 24 ----------------- CDP4ServicesDal/CdpPostOperation.cs | 22 +--------------- .../PostOperationTestFixture.cs | 24 ----------------- CDP4WspDal.Tests/PostOperationTestFixture.cs | 24 ----------------- CDP4WspDal/WSPPostOperation.cs | 22 +--------------- 10 files changed, 18 insertions(+), 151 deletions(-) diff --git a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs index 6ded42c1c..871b511fa 100644 --- a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs @@ -50,17 +50,5 @@ public void VerifyThatConstructorSetsLists() internal class TestPostOperation : PostOperation { - public override List Delete { get; set; } - - public override List Create { get; set; } - - public override List Update { get; set; } - - public override List Copy { get; set; } - - public override void ConstructFromOperation(Operation operation) - { - throw new System.NotImplementedException(); - } } } diff --git a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs index 6ded42c1c..871b511fa 100644 --- a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs @@ -50,17 +50,5 @@ public void VerifyThatConstructorSetsLists() internal class TestPostOperation : PostOperation { - public override List Delete { get; set; } - - public override List Create { get; set; } - - public override List Update { get; set; } - - public override List Copy { get; set; } - - public override void ConstructFromOperation(Operation operation) - { - throw new System.NotImplementedException(); - } } } diff --git a/CDP4DalCommon/Protocol/Operations/PostOperation.cs b/CDP4DalCommon/Protocol/Operations/PostOperation.cs index 36c9bd4d6..7195bc1fa 100644 --- a/CDP4DalCommon/Protocol/Operations/PostOperation.cs +++ b/CDP4DalCommon/Protocol/Operations/PostOperation.cs @@ -24,6 +24,7 @@ namespace CDP4DalCommon.Protocol.Operations { + using System; using System.Collections.Generic; using CDP4Common; @@ -33,38 +34,38 @@ namespace CDP4DalCommon.Protocol.Operations /// /// The abstract super class from which all POST operations derive. /// - public abstract class PostOperation + public class PostOperation { /// /// Initializes a new instance of the class /// - protected PostOperation() + public PostOperation() { - this.Delete = new List(); - this.Create = new List(); - this.Update = new List(); - this.Copy = new List(); + this.Delete = []; + this.Create = []; + this.Update = []; + this.Copy = []; } /// /// Gets or sets the collection of DTOs to delete. /// - public abstract List Delete { get; set; } + public List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - public abstract List Create { get; set; } + public List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - public abstract List Update { get; set; } + public List Update { get; set; } /// /// Gets or sets the collection of DTOs to copy. /// - public abstract List Copy { get; set; } + public List Copy { get; set; } /// /// Populate the current with the content based on the @@ -74,6 +75,9 @@ protected PostOperation() /// The that contains all the s that need to be /// updated to the data-source /// - public abstract void ConstructFromOperation(Operation operation); + public virtual void ConstructFromOperation(Operation operation) + { + throw new NotSupportedException("Cannot construct a PostOperation based on Operation"); + } } } diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 8477f5c22..e2ec98c55 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -1,4 +1,4 @@ - + net47;net471;net472;net48;netstandard2.0;netstandard2.1 diff --git a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj index 1895939a8..ad71df980 100644 --- a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj +++ b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj @@ -11,7 +11,6 @@ - diff --git a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs index 02d0ce7e4..6d469df8d 100644 --- a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs @@ -140,30 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Copy { get; set; } } } } diff --git a/CDP4ServicesDal/CdpPostOperation.cs b/CDP4ServicesDal/CdpPostOperation.cs index afe1adf8c..078310b69 100644 --- a/CDP4ServicesDal/CdpPostOperation.cs +++ b/CDP4ServicesDal/CdpPostOperation.cs @@ -79,26 +79,6 @@ internal CdpPostOperation(IMetaDataProvider metaDataProvider, ISession session) this.session = session; } - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to copy. - /// - public override List Copy { get; set; } - /// /// Populate the current with the content based on the /// provided @@ -111,7 +91,7 @@ public override void ConstructFromOperation(Operation operation) { if (operation.ModifiedThing == null) { - throw new ArgumentNullException("operation", "The operation may not be null"); + throw new ArgumentNullException(nameof(operation), "The operation may not be null"); } switch (operation.OperationKind) diff --git a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs index 1a41f72a7..581253c87 100644 --- a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs @@ -140,30 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Copy { get; set; } - - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } } } } diff --git a/CDP4WspDal.Tests/PostOperationTestFixture.cs b/CDP4WspDal.Tests/PostOperationTestFixture.cs index 1a41f72a7..581253c87 100644 --- a/CDP4WspDal.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/PostOperationTestFixture.cs @@ -140,30 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Copy { get; set; } - - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } } } } diff --git a/CDP4WspDal/WSPPostOperation.cs b/CDP4WspDal/WSPPostOperation.cs index 8888b2b27..df2c96eee 100644 --- a/CDP4WspDal/WSPPostOperation.cs +++ b/CDP4WspDal/WSPPostOperation.cs @@ -59,26 +59,6 @@ public WspPostOperation(IMetaDataProvider metaDataProvider) this.metaDataProvider = metaDataProvider; } - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to copy. - /// - public override List Copy { get; set; } - /// /// Populate this with the correct setup for the OCDT protocol /// @@ -89,7 +69,7 @@ public override void ConstructFromOperation(Operation operation) { if (operation.ModifiedThing == null) { - throw new ArgumentNullException("operation"); + throw new ArgumentNullException(nameof(operation)); } if (operation.OperationKind == OperationKind.Update && operation.OriginalThing == null) From 09d9365712f440b72c9943e8446b83d3ee313582 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 11:39:34 +0100 Subject: [PATCH 10/34] Improved deserialization of postoperation --- .../JsonConverter/PostOperationJsonConverter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs index 4da5579bd..7261c4eda 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -26,6 +26,7 @@ namespace CDP4DalJsonSerializer.JsonConverter { using System; using System.IO; + using System.Runtime.Serialization; using System.Text.Json; using System.Text.Json.Serialization; @@ -88,14 +89,14 @@ public override PostOperation Read(ref Utf8JsonReader reader, Type typeToConvert throw new InvalidDataException("The data object in the JSON array could not be cast to a JObject type."); } - var initializedPostOperation = Activator.CreateInstance(typeToConvert); - - if (initializedPostOperation is not PostOperation postOperation) + if (!typeof(PostOperation).IsAssignableFrom(typeToConvert)) { Logger.Error($"The request Type {typeToConvert.Name} is not a PostOperation"); throw new InvalidDataException($"The request Type {typeToConvert.Name} is not a PostOperation"); } + var postOperation = (PostOperation)FormatterServices.GetUninitializedObject(typeToConvert); + jsonElement.Value.DeserializePostOperation(postOperation, options); return postOperation; } From f155be5af762b12ff0542bb99f8b612612ff6a89 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 11:43:59 +0100 Subject: [PATCH 11/34] Remove useless constructor of PostOperation --- .../Protocol/Operations/PostOperation.cs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/CDP4DalCommon/Protocol/Operations/PostOperation.cs b/CDP4DalCommon/Protocol/Operations/PostOperation.cs index 7195bc1fa..6894d2a27 100644 --- a/CDP4DalCommon/Protocol/Operations/PostOperation.cs +++ b/CDP4DalCommon/Protocol/Operations/PostOperation.cs @@ -36,36 +36,25 @@ namespace CDP4DalCommon.Protocol.Operations /// public class PostOperation { - /// - /// Initializes a new instance of the class - /// - public PostOperation() - { - this.Delete = []; - this.Create = []; - this.Update = []; - this.Copy = []; - } - /// /// Gets or sets the collection of DTOs to delete. /// - public List Delete { get; set; } + public List Delete { get; set; } = []; /// /// Gets or sets the collection of DTOs to create. /// - public List Create { get; set; } + public List Create { get; set; } = []; /// /// Gets or sets the collection of DTOs to update. /// - public List Update { get; set; } + public List Update { get; set; } = []; /// /// Gets or sets the collection of DTOs to copy. /// - public List Copy { get; set; } + public List Copy { get; set; } = []; /// /// Populate the current with the content based on the From ebafaa49d6c0931ff18ef07be0a6e0d9764d1a56 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 13:01:12 +0100 Subject: [PATCH 12/34] Requested changes, fix build and improved PropertySerialization --- .../PostOperationJsonConverter.cs | 8 +- .../ActionItemResolver.cs | 28 +- .../ActualFiniteStateListResolver.cs | 6 +- .../ActualFiniteStateResolver.cs | 6 +- .../AutoGenDtoDeserializer/AliasResolver.cs | 10 +- .../AndExpressionResolver.cs | 4 +- .../ApprovalResolver.cs | 16 +- .../ArrayParameterTypeResolver.cs | 16 +- .../BinaryNoteResolver.cs | 16 +- .../BinaryRelationshipResolver.cs | 12 +- .../BinaryRelationshipRuleResolver.cs | 20 +- .../AutoGenDtoDeserializer/BookResolver.cs | 12 +- .../BooleanParameterTypeResolver.cs | 12 +- .../AutoGenDtoDeserializer/BoundsResolver.cs | 14 +- .../BuiltInRuleVerificationResolver.cs | 10 +- .../CategoryResolver.cs | 12 +- .../ChangeProposalResolver.cs | 24 +- .../ChangeRequestResolver.cs | 22 +- .../CitationResolver.cs | 14 +- .../AutoGenDtoDeserializer/ColorResolver.cs | 12 +- .../CommonFileStoreResolver.cs | 10 +- .../CompoundParameterTypeResolver.cs | 14 +- .../ConstantResolver.cs | 12 +- .../ContractChangeNoticeResolver.cs | 24 +- .../CyclicRatioScaleResolver.cs | 28 +- .../DateParameterTypeResolver.cs | 12 +- .../DateTimeParameterTypeResolver.cs | 12 +- .../DecompositionRuleResolver.cs | 14 +- .../DefinitionResolver.cs | 8 +- ...ependentParameterTypeAssignmentResolver.cs | 6 +- .../DerivedQuantityKindResolver.cs | 16 +- .../DerivedUnitResolver.cs | 10 +- .../DiagramCanvasResolver.cs | 8 +- .../DiagramEdgeResolver.cs | 10 +- .../DiagramObjectResolver.cs | 10 +- .../DomainFileStoreResolver.cs | 12 +- .../DomainOfExpertiseGroupResolver.cs | 10 +- .../DomainOfExpertiseResolver.cs | 10 +- .../ElementDefinitionResolver.cs | 10 +- .../ElementUsageResolver.cs | 14 +- .../EmailAddressResolver.cs | 8 +- ...ineeringModelDataDiscussionItemResolver.cs | 12 +- .../EngineeringModelDataNoteResolver.cs | 12 +- .../EngineeringModelResolver.cs | 8 +- .../EngineeringModelSetupResolver.cs | 14 +- .../EnumerationParameterTypeResolver.cs | 14 +- .../EnumerationValueDefinitionResolver.cs | 8 +- .../ExclusiveOrExpressionResolver.cs | 4 +- .../ExternalIdentifierMapResolver.cs | 14 +- .../AutoGenDtoDeserializer/FileResolver.cs | 6 +- .../FileRevisionResolver.cs | 12 +- .../FileTypeResolver.cs | 12 +- .../AutoGenDtoDeserializer/FolderResolver.cs | 12 +- .../GlossaryResolver.cs | 10 +- .../AutoGenDtoDeserializer/GoalResolver.cs | 8 +- .../HyperLinkResolver.cs | 10 +- .../IdCorrespondenceResolver.cs | 8 +- ...ependentParameterTypeAssignmentResolver.cs | 6 +- .../IntervalScaleResolver.cs | 26 +- .../IterationResolver.cs | 6 +- .../IterationSetupResolver.cs | 14 +- .../LinearConversionUnitResolver.cs | 14 +- .../LogEntryChangelogItemResolver.cs | 10 +- .../LogarithmicScaleResolver.cs | 34 +- .../MappingToReferenceScaleResolver.cs | 8 +- .../ModelLogEntryResolver.cs | 12 +- .../ModelReferenceDataLibraryResolver.cs | 8 +- .../ModellingThingReferenceResolver.cs | 8 +- .../MultiRelationshipResolver.cs | 8 +- .../MultiRelationshipRuleResolver.cs | 16 +- .../NaturalLanguageResolver.cs | 10 +- .../NestedElementResolver.cs | 8 +- .../NestedParameterResolver.cs | 14 +- .../NotExpressionResolver.cs | 6 +- .../AutoGenDtoDeserializer/OptionResolver.cs | 8 +- .../OrExpressionResolver.cs | 4 +- .../OrdinalScaleResolver.cs | 28 +- .../OrganizationResolver.cs | 10 +- .../OrganizationalParticipantResolver.cs | 6 +- .../OwnedStyleResolver.cs | 8 +- .../AutoGenDtoDeserializer/PageResolver.cs | 12 +- .../ParameterGroupResolver.cs | 6 +- .../ParameterOverrideResolver.cs | 8 +- .../ParameterOverrideValueSetResolver.cs | 8 +- .../ParameterResolver.cs | 14 +- .../ParameterSubscriptionResolver.cs | 6 +- .../ParameterSubscriptionValueSetResolver.cs | 8 +- .../ParameterTypeComponentResolver.cs | 8 +- .../ParameterValueSetResolver.cs | 6 +- .../ParameterizedCategoryRuleResolver.cs | 12 +- .../ParametricConstraintResolver.cs | 4 +- .../ParticipantPermissionResolver.cs | 10 +- .../ParticipantResolver.cs | 12 +- .../ParticipantRoleResolver.cs | 10 +- .../PersonPermissionResolver.cs | 10 +- .../AutoGenDtoDeserializer/PersonResolver.cs | 18 +- .../PersonRoleResolver.cs | 10 +- .../AutoGenDtoDeserializer/PointResolver.cs | 10 +- .../PossibleFiniteStateListResolver.cs | 10 +- .../PossibleFiniteStateResolver.cs | 8 +- .../PrefixedUnitResolver.cs | 10 +- .../PublicationResolver.cs | 6 +- .../QuantityKindFactorResolver.cs | 8 +- .../RatioScaleResolver.cs | 26 +- .../ReferenceSourceResolver.cs | 16 +- .../ReferencerRuleResolver.cs | 16 +- .../RelationalExpressionResolver.cs | 8 +- .../RelationshipParameterValueResolver.cs | 6 +- .../RequestForDeviationResolver.cs | 22 +- .../RequestForWaiverResolver.cs | 22 +- .../RequirementResolver.cs | 12 +- ...irementsContainerParameterValueResolver.cs | 6 +- .../RequirementsGroupResolver.cs | 10 +- .../RequirementsSpecificationResolver.cs | 12 +- .../ReviewItemDiscrepancyResolver.cs | 22 +- .../RuleVerificationListResolver.cs | 10 +- .../RuleViolationResolver.cs | 6 +- .../SampledFunctionParameterTypeResolver.cs | 12 +- .../ScaleReferenceQuantityValueResolver.cs | 8 +- .../ScaleValueDefinitionResolver.cs | 10 +- .../AutoGenDtoDeserializer/SectionResolver.cs | 12 +- .../SharedStyleResolver.cs | 8 +- .../SimpleParameterValueResolver.cs | 6 +- .../SimpleQuantityKindResolver.cs | 16 +- .../SimpleUnitResolver.cs | 10 +- .../SiteDirectoryDataAnnotationResolver.cs | 14 +- ...SiteDirectoryDataDiscussionItemResolver.cs | 12 +- .../SiteDirectoryResolver.cs | 12 +- .../SiteDirectoryThingReferenceResolver.cs | 8 +- .../SiteLogEntryResolver.cs | 12 +- .../SiteReferenceDataLibraryResolver.cs | 10 +- .../SolutionResolver.cs | 14 +- .../SpecializedQuantityKindResolver.cs | 18 +- .../StakeHolderValueMapResolver.cs | 8 +- .../StakeHolderValueMapSettingsResolver.cs | 4 +- .../StakeholderResolver.cs | 8 +- .../StakeholderValueResolver.cs | 8 +- .../TelephoneNumberResolver.cs | 6 +- .../AutoGenDtoDeserializer/TermResolver.cs | 10 +- .../TextParameterTypeResolver.cs | 12 +- .../TextualNoteResolver.cs | 16 +- .../TimeOfDayParameterTypeResolver.cs | 12 +- .../UnitFactorResolver.cs | 8 +- .../UnitPrefixResolver.cs | 12 +- .../UserPreferenceResolver.cs | 8 +- .../UserRuleVerificationResolver.cs | 10 +- .../ValueGroupResolver.cs | 8 +- .../ActionItemSerializer.cs | 1181 +++++------- .../ActualFiniteStateListSerializer.cs | 603 +++--- .../ActualFiniteStateSerializer.cs | 467 ++--- .../AutoGenDtoSerializer/AliasSerializer.cs | 442 ++--- .../AndExpressionSerializer.cs | 440 ++--- .../ApprovalSerializer.cs | 472 ++--- .../ArrayParameterTypeSerializer.cs | 1131 +++++------ .../BinaryNoteSerializer.cs | 533 +++-- .../BinaryRelationshipRuleSerializer.cs | 936 ++++----- .../BinaryRelationshipSerializer.cs | 599 +++--- .../AutoGenDtoSerializer/BookSerializer.cs | 550 +++--- .../BooleanParameterTypeSerializer.cs | 895 ++++----- .../AutoGenDtoSerializer/BoundsSerializer.cs | 450 ++--- .../BuiltInRuleVerificationSerializer.cs | 620 +++--- .../CategorySerializer.cs | 968 +++++----- .../ChangeProposalSerializer.cs | 1079 +++++------ .../ChangeRequestSerializer.cs | 1039 +++++----- .../CitationSerializer.cs | 496 +++-- .../AutoGenDtoSerializer/ColorSerializer.cs | 469 ++--- .../CommonFileStoreSerializer.cs | 600 +++--- .../CompoundParameterTypeSerializer.cs | 1021 +++++----- .../ConstantSerializer.cs | 977 +++++----- .../ContractChangeNoticeSerializer.cs | 1079 +++++------ .../CyclicRatioScaleSerializer.cs | 1362 ++++++------- .../DateParameterTypeSerializer.cs | 895 ++++----- .../DateTimeParameterTypeSerializer.cs | 895 ++++----- .../DecompositionRuleSerializer.cs | 983 +++++----- .../DefinitionSerializer.cs | 648 +++---- ...endentParameterTypeAssignmentSerializer.cs | 351 ++-- .../DerivedQuantityKindSerializer.cs | 1101 +++++------ .../DerivedUnitSerializer.cs | 836 ++++---- .../DiagramCanvasSerializer.cs | 506 +++-- .../DiagramEdgeSerializer.cs | 838 ++++---- .../DiagramObjectSerializer.cs | 783 ++++---- .../DomainFileStoreSerializer.cs | 627 +++--- .../DomainOfExpertiseGroupSerializer.cs | 846 ++++---- .../DomainOfExpertiseSerializer.cs | 848 ++++---- .../ElementDefinitionSerializer.cs | 1167 ++++++----- .../ElementUsageSerializer.cs | 1062 +++++----- .../EmailAddressSerializer.cs | 415 ++-- ...eeringModelDataDiscussionItemSerializer.cs | 504 +++-- .../EngineeringModelDataNoteSerializer.cs | 626 +++--- .../EngineeringModelSerializer.cs | 901 ++++----- .../EngineeringModelSetupSerializer.cs | 1280 ++++++------ .../EnumerationParameterTypeSerializer.cs | 1011 +++++----- .../EnumerationValueDefinitionSerializer.cs | 648 +++---- .../ExclusiveOrExpressionSerializer.cs | 440 ++--- .../ExternalIdentifierMapSerializer.cs | 676 +++---- .../FileRevisionSerializer.cs | 649 +++---- .../AutoGenDtoSerializer/FileSerializer.cs | 599 +++--- .../FileTypeSerializer.cs | 883 ++++----- .../AutoGenDtoSerializer/FolderSerializer.cs | 568 +++--- .../GlossarySerializer.cs | 903 ++++----- .../AutoGenDtoSerializer/GoalSerializer.cs | 628 +++--- .../HyperLinkSerializer.cs | 442 ++--- .../IdCorrespondenceSerializer.cs | 415 ++-- ...endentParameterTypeAssignmentSerializer.cs | 351 ++-- .../IntervalScaleSerializer.cs | 1227 ++++++------ .../IterationSerializer.cs | 1708 ++++++++--------- .../IterationSetupSerializer.cs | 768 ++++---- .../LinearConversionUnitSerializer.cs | 863 ++++----- .../LogEntryChangelogItemSerializer.cs | 375 ++-- .../LogarithmicScaleSerializer.cs | 1466 +++++++------- .../MappingToReferenceScaleSerializer.cs | 415 ++-- .../ModelLogEntrySerializer.cs | 896 ++++----- .../ModelReferenceDataLibrarySerializer.cs | 1367 ++++++------- .../ModellingThingReferenceSerializer.cs | 384 ++-- .../MultiRelationshipRuleSerializer.cs | 979 +++++----- .../MultiRelationshipSerializer.cs | 624 +++--- .../NaturalLanguageSerializer.cs | 442 ++--- .../NestedElementSerializer.cs | 573 +++--- .../NestedParameterSerializer.cs | 595 +++--- .../NotExpressionSerializer.cs | 388 ++-- .../AutoGenDtoSerializer/OptionSerializer.cs | 866 ++++----- .../OrExpressionSerializer.cs | 440 ++--- .../OrdinalScaleSerializer.cs | 1364 ++++++------- .../OrganizationSerializer.cs | 442 ++--- .../OrganizationalParticipantSerializer.cs | 298 ++- .../OwnedStyleSerializer.cs | 1027 +++++----- .../AutoGenDtoSerializer/PageSerializer.cs | 550 +++--- .../ParameterGroupSerializer.cs | 487 +++-- .../ParameterOverrideSerializer.cs | 573 +++--- .../ParameterOverrideValueSetSerializer.cs | 510 +++-- .../ParameterSerializer.cs | 1030 +++++----- .../ParameterSubscriptionSerializer.cs | 467 ++--- ...ParameterSubscriptionValueSetSerializer.cs | 434 ++--- .../ParameterTypeComponentSerializer.cs | 514 +++-- .../ParameterValueSetSerializer.cs | 671 +++---- .../ParameterizedCategoryRuleSerializer.cs | 869 ++++----- .../ParametricConstraintSerializer.cs | 505 +++-- .../ParticipantPermissionSerializer.cs | 442 ++--- .../ParticipantRoleSerializer.cs | 838 ++++---- .../ParticipantSerializer.cs | 548 +++--- .../PersonPermissionSerializer.cs | 442 ++--- .../PersonRoleSerializer.cs | 838 ++++---- .../AutoGenDtoSerializer/PersonSerializer.cs | 1176 +++++------- .../AutoGenDtoSerializer/PointSerializer.cs | 406 ++-- .../PossibleFiniteStateListSerializer.cs | 958 +++++---- .../PossibleFiniteStateSerializer.cs | 648 +++---- .../PrefixedUnitSerializer.cs | 741 ++++--- .../PublicationSerializer.cs | 546 +++--- .../QuantityKindFactorSerializer.cs | 415 ++-- .../RatioScaleSerializer.cs | 1227 ++++++------ .../ReferenceSourceSerializer.cs | 1161 +++++------ .../ReferencerRuleSerializer.cs | 979 +++++----- .../RelationalExpressionSerializer.cs | 533 +++-- .../RelationshipParameterValueSerializer.cs | 454 ++--- .../RequestForDeviationSerializer.cs | 1039 +++++----- .../RequestForWaiverSerializer.cs | 1039 +++++----- .../RequirementSerializer.cs | 1076 +++++------ ...ementsContainerParameterValueSerializer.cs | 454 ++--- .../RequirementsGroupSerializer.cs | 972 +++++----- .../RequirementsSpecificationSerializer.cs | 1068 +++++------ .../ReviewItemDiscrepancySerializer.cs | 1120 +++++------ .../RuleVerificationListSerializer.cs | 838 ++++---- .../RuleViolationSerializer.cs | 467 ++--- .../SampledFunctionParameterTypeSerializer.cs | 675 +++---- .../ScaleReferenceQuantityValueSerializer.cs | 415 ++-- .../ScaleValueDefinitionSerializer.cs | 741 ++++--- .../AutoGenDtoSerializer/SectionSerializer.cs | 550 +++--- .../SharedStyleSerializer.cs | 1027 +++++----- .../SimpleParameterValueSerializer.cs | 506 +++-- .../SimpleQuantityKindSerializer.cs | 1032 +++++----- .../SimpleUnitSerializer.cs | 741 ++++--- .../SiteDirectoryDataAnnotationSerializer.cs | 572 +++--- ...teDirectoryDataDiscussionItemSerializer.cs | 504 +++-- .../SiteDirectorySerializer.cs | 1410 +++++++------- .../SiteDirectoryThingReferenceSerializer.cs | 384 ++-- .../SiteLogEntrySerializer.cs | 896 ++++----- .../SiteReferenceDataLibrarySerializer.cs | 1516 +++++++-------- .../SolutionSerializer.cs | 450 ++--- .../SpecializedQuantityKindSerializer.cs | 1071 +++++------ .../StakeHolderValueMapSerializer.cs | 1041 +++++----- .../StakeHolderValueMapSettingsSerializer.cs | 538 +++--- .../StakeholderSerializer.cs | 783 ++++---- .../StakeholderValueSerializer.cs | 628 +++--- .../TelephoneNumberSerializer.cs | 467 ++--- .../AutoGenDtoSerializer/TermSerializer.cs | 741 ++++--- .../TextParameterTypeSerializer.cs | 895 ++++----- .../TextualNoteSerializer.cs | 533 +++-- .../TimeOfDayParameterTypeSerializer.cs | 895 ++++----- .../UnitFactorSerializer.cs | 415 ++-- .../UnitPrefixSerializer.cs | 808 ++++---- .../UserPreferenceSerializer.cs | 415 ++-- .../UserRuleVerificationSerializer.cs | 620 +++--- .../ValueGroupSerializer.cs | 628 +++--- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 1 + .../PostOperationTestFixture.cs | 24 - 295 files changed, 50277 insertions(+), 60609 deletions(-) diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs index 7261c4eda..af260a774 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -108,7 +108,7 @@ public override PostOperation Read(ref Utf8JsonReader reader, Type typeToConvert public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSerializerOptions options) { writer.WriteStartObject(); - writer.WriteStartArray("_delete"); + writer.WriteStartArray("_delete"u8); foreach (var toDelete in value.Delete) { @@ -116,7 +116,7 @@ public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSeria } writer.WriteEndArray(); - writer.WriteStartArray("_create"); + writer.WriteStartArray("_create"u8); foreach (var toCreate in value.Create) { @@ -124,7 +124,7 @@ public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSeria } writer.WriteEndArray(); - writer.WriteStartArray("_update"); + writer.WriteStartArray("_update"u8); foreach (var toUpdate in value.Update) { @@ -135,7 +135,7 @@ public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSeria if (!this.ignoreCopyProperty) { - writer.WriteStartArray("_copy"); + writer.WriteStartArray("_copy"u8); foreach (var toCopy in value.Copy) { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index 7e7c2b211..c4c630f61 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(actioneeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale actionee property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale actionee property of the actionItem {id} is null", actionItem.Iid); } else { @@ -87,7 +87,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale author property of the actionItem {id} is null", actionItem.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale classification property of the actionItem {id} is null", actionItem.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(closeOutStatementProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale closeOutStatement property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale closeOutStatement property of the actionItem {id} is null", actionItem.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale content property of the actionItem {id} is null", actionItem.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale createdOn property of the actionItem {id} is null", actionItem.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(dueDateProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale dueDate property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale dueDate property of the actionItem {id} is null", actionItem.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale languageCode property of the actionItem {id} is null", actionItem.Iid); } else { @@ -215,7 +215,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the actionItem {id} is null", actionItem.Iid); } else { @@ -227,7 +227,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale owner property of the actionItem {id} is null", actionItem.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale shortName property of the actionItem {id} is null", actionItem.Iid); } else { @@ -279,7 +279,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale status property of the actionItem {id} is null", actionItem.Iid); } else { @@ -291,7 +291,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale thingPreference property of the actionItem {id} is null", actionItem.Iid); } else { @@ -303,7 +303,7 @@ public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the actionItem {id} is null", actionItem.Iid); + Logger.Trace("The non-nullabale title property of the actionItem {id} is null", actionItem.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index 9ff4be99c..5f599126e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -99,7 +99,7 @@ public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement js { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + Logger.Trace("The non-nullabale owner property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); } else { @@ -128,7 +128,7 @@ public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index 152686837..97474b0d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonEl { if(kindProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale kind property of the actualFiniteState {id} is null", actualFiniteState.Iid); + Logger.Trace("The non-nullabale kind property of the actualFiniteState {id} is null", actualFiniteState.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the actualFiniteState {id} is null", actualFiniteState.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteState {id} is null", actualFiniteState.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the actualFiniteState {id} is null", actualFiniteState.Iid); + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteState {id} is null", actualFiniteState.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index 56a4aacfd..bb0f859c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the alias {id} is null", alias.Iid); + Logger.Trace("The non-nullabale content property of the alias {id} is null", alias.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { if(isSynonymProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isSynonym property of the alias {id} is null", alias.Iid); + Logger.Trace("The non-nullabale isSynonym property of the alias {id} is null", alias.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the alias {id} is null", alias.Iid); + Logger.Trace("The non-nullabale languageCode property of the alias {id} is null", alias.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the alias {id} is null", alias.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the alias {id} is null", alias.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the alias {id} is null", alias.Iid); + Logger.Trace("The non-nullabale thingPreference property of the alias {id} is null", alias.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index 1ea4589f2..51a6c7418 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.AndExpression FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the andExpression {id} is null", andExpression.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the andExpression {id} is null", andExpression.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.AndExpression FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the andExpression {id} is null", andExpression.Iid); + Logger.Trace("The non-nullabale thingPreference property of the andExpression {id} is null", andExpression.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index a7223295e..1a8acf813 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale author property of the approval {id} is null", approval.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale classification property of the approval {id} is null", approval.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale content property of the approval {id} is null", approval.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale createdOn property of the approval {id} is null", approval.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale languageCode property of the approval {id} is null", approval.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the approval {id} is null", approval.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale owner property of the approval {id} is null", approval.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the approval {id} is null", approval.Iid); + Logger.Trace("The non-nullabale thingPreference property of the approval {id} is null", approval.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index c159b1b55..7468710cc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -125,7 +125,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -137,7 +137,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(isFinalizedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isFinalized property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale isFinalized property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -149,7 +149,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(isTensorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isTensor property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale isTensor property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -161,7 +161,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -173,7 +173,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale name property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -185,7 +185,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -197,7 +197,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { @@ -209,7 +209,7 @@ public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonE { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the arrayParameterType {id} is null", arrayParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the arrayParameterType {id} is null", arrayParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index 0e4aa3f37..84fd7954e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(captionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale caption property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale caption property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -87,7 +87,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale createdOn property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(fileTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale fileType property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale fileType property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale name property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale owner property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale shortName property of the binaryNote {id} is null", binaryNote.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the binaryNote {id} is null", binaryNote.Iid); + Logger.Trace("The non-nullabale thingPreference property of the binaryNote {id} is null", binaryNote.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index 2f4ce317a..b324a7a2d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -91,7 +91,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale name property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale owner property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(sourceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale source property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale source property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(targetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale target property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale target property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonE { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the binaryRelationship {id} is null", binaryRelationship.Iid); + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationship {id} is null", binaryRelationship.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index d27b9cbf7..ee15b3b01 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -99,7 +99,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(forwardRelationshipNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale forwardRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale forwardRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(inverseRelationshipNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale inverseRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale inverseRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale name property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale relationshipCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale relationshipCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale shortName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(sourceCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale sourceCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale sourceCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(targetCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale targetCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale targetCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { @@ -215,7 +215,7 @@ public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement j { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index 02a849837..ec7c73f59 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale createdOn property of the book {id} is null", book.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the book {id} is null", book.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale name property of the book {id} is null", book.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale owner property of the book {id} is null", book.Iid); } else { @@ -144,7 +144,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale shortName property of the book {id} is null", book.Iid); } else { @@ -156,7 +156,7 @@ public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the book {id} is null", book.Iid); + Logger.Trace("The non-nullabale thingPreference property of the book {id} is null", book.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index 78a4acd3d..3adccd1fb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale name property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the booleanParameterType {id} is null", booleanParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the booleanParameterType {id} is null", booleanParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index 040a11bd0..2ab0b5091 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(heightProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale height property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale height property of the bounds {id} is null", bounds.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the bounds {id} is null", bounds.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale name property of the bounds {id} is null", bounds.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale thingPreference property of the bounds {id} is null", bounds.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(widthProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale width property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale width property of the bounds {id} is null", bounds.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(xProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale x property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale x property of the bounds {id} is null", bounds.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { if(yProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale y property of the bounds {id} is null", bounds.Iid); + Logger.Trace("The non-nullabale y property of the bounds {id} is null", bounds.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index e86891285..98ff206db 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement { if(isActiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isActive property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + Logger.Trace("The non-nullabale isActive property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + Logger.Trace("The non-nullabale name property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + Logger.Trace("The non-nullabale status property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + Logger.Trace("The non-nullabale thingPreference property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index babc936ae..136302465 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(isAbstractProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isAbstract property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale isAbstract property of the category {id} is null", category.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the category {id} is null", category.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the category {id} is null", category.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale name property of the category {id} is null", category.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale shortName property of the category {id} is null", category.Iid); } else { @@ -183,7 +183,7 @@ public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the category {id} is null", category.Iid); + Logger.Trace("The non-nullabale thingPreference property of the category {id} is null", category.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index fae894ee8..d7fd3c3d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale author property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(changeRequestProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale changeRequest property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale changeRequest property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale classification property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale content property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale createdOn property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale languageCode property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale owner property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale shortName property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale status property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale thingPreference property of the changeProposal {id} is null", changeProposal.Iid); } else { @@ -267,7 +267,7 @@ public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonEleme { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the changeProposal {id} is null", changeProposal.Iid); + Logger.Trace("The non-nullabale title property of the changeProposal {id} is null", changeProposal.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index e7cd93b16..65ee35157 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale author property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale classification property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale content property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale createdOn property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale languageCode property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale owner property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale shortName property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -231,7 +231,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale status property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale thingPreference property of the changeRequest {id} is null", changeRequest.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElemen { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the changeRequest {id} is null", changeRequest.Iid); + Logger.Trace("The non-nullabale title property of the changeRequest {id} is null", changeRequest.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index 7d4b2e3bd..aef860fc3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(isAdaptationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isAdaptation property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale isAdaptation property of the citation {id} is null", citation.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(locationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale location property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale location property of the citation {id} is null", citation.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the citation {id} is null", citation.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(remarkProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale remark property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale remark property of the citation {id} is null", citation.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale shortName property of the citation {id} is null", citation.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(sourceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale source property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale source property of the citation {id} is null", citation.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the citation {id} is null", citation.Iid); + Logger.Trace("The non-nullabale thingPreference property of the citation {id} is null", citation.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index 10ad217a9..ca61938e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(blueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale blue property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale blue property of the color {id} is null", color.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(greenProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale green property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale green property of the color {id} is null", color.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the color {id} is null", color.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale name property of the color {id} is null", color.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(redProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale red property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale red property of the color {id} is null", color.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the color {id} is null", color.Iid); + Logger.Trace("The non-nullabale thingPreference property of the color {id} is null", color.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index 0b18fb310..0969d7170 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElem { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the commonFileStore {id} is null", commonFileStore.Iid); + Logger.Trace("The non-nullabale createdOn property of the commonFileStore {id} is null", commonFileStore.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the commonFileStore {id} is null", commonFileStore.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the commonFileStore {id} is null", commonFileStore.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElem { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the commonFileStore {id} is null", commonFileStore.Iid); + Logger.Trace("The non-nullabale name property of the commonFileStore {id} is null", commonFileStore.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElem { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the commonFileStore {id} is null", commonFileStore.Iid); + Logger.Trace("The non-nullabale owner property of the commonFileStore {id} is null", commonFileStore.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the commonFileStore {id} is null", commonFileStore.Iid); + Logger.Trace("The non-nullabale thingPreference property of the commonFileStore {id} is null", commonFileStore.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index 565b835c6..39482bbd2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -120,7 +120,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -132,7 +132,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(isFinalizedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isFinalized property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale isFinalized property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -144,7 +144,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -156,7 +156,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale name property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -168,7 +168,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -180,7 +180,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { @@ -192,7 +192,7 @@ public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the compoundParameterType {id} is null", compoundParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the compoundParameterType {id} is null", compoundParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index c3219160a..8b0bdcc64 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the constant {id} is null", constant.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the constant {id} is null", constant.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale name property of the constant {id} is null", constant.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale parameterType property of the constant {id} is null", constant.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale shortName property of the constant {id} is null", constant.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the constant {id} is null", constant.Iid); + Logger.Trace("The non-nullabale thingPreference property of the constant {id} is null", constant.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index b4aa0b635..2e9024570 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale author property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(changeProposalProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale changeProposal property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale changeProposal property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale classification property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale content property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale createdOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale languageCode property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale owner property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale shortName property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale status property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale thingPreference property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { @@ -267,7 +267,7 @@ public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jso { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + Logger.Trace("The non-nullabale title property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index e479477f8..130ac64a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMaximumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale isMaximumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMinimumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale isMinimumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maximumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale maximumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minimumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale minimumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(modulusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modulus property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale modulus property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale name property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale negativeValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale negativeValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(numberSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale numberSet property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale numberSet property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale positiveValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale positiveValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale shortName property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { @@ -271,7 +271,7 @@ public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonEle { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + Logger.Trace("The non-nullabale unit property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index cedfd804c..0d19d7dbf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the dateParameterType {id} is null", dateParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the dateParameterType {id} is null", dateParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale name property of the dateParameterType {id} is null", dateParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the dateParameterType {id} is null", dateParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the dateParameterType {id} is null", dateParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the dateParameterType {id} is null", dateParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the dateParameterType {id} is null", dateParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index 397201bff..259457721 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale name property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index 840efd27d..a179dc8eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(containingCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale containingCategory property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale containingCategory property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(minContainedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minContained property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale minContained property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale name property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale shortName property of the decompositionRule {id} is null", decompositionRule.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the decompositionRule {id} is null", decompositionRule.Iid); + Logger.Trace("The non-nullabale thingPreference property of the decompositionRule {id} is null", decompositionRule.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 9a90885b1..3dbfce7c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the definition {id} is null", definition.Iid); + Logger.Trace("The non-nullabale content property of the definition {id} is null", definition.Iid); } else { @@ -108,7 +108,7 @@ public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the definition {id} is null", definition.Iid); + Logger.Trace("The non-nullabale languageCode property of the definition {id} is null", definition.Iid); } else { @@ -120,7 +120,7 @@ public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the definition {id} is null", definition.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the definition {id} is null", definition.Iid); } else { @@ -137,7 +137,7 @@ public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the definition {id} is null", definition.Iid); + Logger.Trace("The non-nullabale thingPreference property of the definition {id} is null", definition.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index b424f62a8..6cba47589 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(Jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(Jso { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale parameterType property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(Jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale thingPreference property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index 351ed6f2a..90fecb3f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(defaultScaleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale defaultScale property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale defaultScale property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale name property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale quantityDimensionSymbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -188,7 +188,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale shortName property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -200,7 +200,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale symbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { @@ -212,7 +212,7 @@ public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement json { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + Logger.Trace("The non-nullabale thingPreference property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index 843692006..4346800f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the derivedUnit {id} is null", derivedUnit.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the derivedUnit {id} is null", derivedUnit.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the derivedUnit {id} is null", derivedUnit.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the derivedUnit {id} is null", derivedUnit.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the derivedUnit {id} is null", derivedUnit.Iid); + Logger.Trace("The non-nullabale name property of the derivedUnit {id} is null", derivedUnit.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the derivedUnit {id} is null", derivedUnit.Iid); + Logger.Trace("The non-nullabale shortName property of the derivedUnit {id} is null", derivedUnit.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the derivedUnit {id} is null", derivedUnit.Iid); + Logger.Trace("The non-nullabale thingPreference property of the derivedUnit {id} is null", derivedUnit.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index eb1f7514d..7ded4b613 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElemen { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + Logger.Trace("The non-nullabale createdOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the diagramCanvas {id} is null", diagramCanvas.Iid); + Logger.Trace("The non-nullabale name property of the diagramCanvas {id} is null", diagramCanvas.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the diagramCanvas {id} is null", diagramCanvas.Iid); + Logger.Trace("The non-nullabale thingPreference property of the diagramCanvas {id} is null", diagramCanvas.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index c5e8aff11..dd993465d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -119,7 +119,7 @@ public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the diagramEdge {id} is null", diagramEdge.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the diagramEdge {id} is null", diagramEdge.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the diagramEdge {id} is null", diagramEdge.Iid); + Logger.Trace("The non-nullabale name property of the diagramEdge {id} is null", diagramEdge.Iid); } else { @@ -160,7 +160,7 @@ public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { if(sourceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale source property of the diagramEdge {id} is null", diagramEdge.Iid); + Logger.Trace("The non-nullabale source property of the diagramEdge {id} is null", diagramEdge.Iid); } else { @@ -172,7 +172,7 @@ public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { if(targetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale target property of the diagramEdge {id} is null", diagramEdge.Iid); + Logger.Trace("The non-nullabale target property of the diagramEdge {id} is null", diagramEdge.Iid); } else { @@ -184,7 +184,7 @@ public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the diagramEdge {id} is null", diagramEdge.Iid); + Logger.Trace("The non-nullabale thingPreference property of the diagramEdge {id} is null", diagramEdge.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index be0d77768..4477d81ce 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElemen { if(documentationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale documentation property of the diagramObject {id} is null", diagramObject.Iid); + Logger.Trace("The non-nullabale documentation property of the diagramObject {id} is null", diagramObject.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the diagramObject {id} is null", diagramObject.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the diagramObject {id} is null", diagramObject.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the diagramObject {id} is null", diagramObject.Iid); + Logger.Trace("The non-nullabale name property of the diagramObject {id} is null", diagramObject.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElemen { if(resolutionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale resolution property of the diagramObject {id} is null", diagramObject.Iid); + Logger.Trace("The non-nullabale resolution property of the diagramObject {id} is null", diagramObject.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the diagramObject {id} is null", diagramObject.Iid); + Logger.Trace("The non-nullabale thingPreference property of the diagramObject {id} is null", diagramObject.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index 5c95e266f..1f173b3d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale createdOn property of the domainFileStore {id} is null", domainFileStore.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(isHiddenProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isHidden property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale isHidden property of the domainFileStore {id} is null", domainFileStore.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the domainFileStore {id} is null", domainFileStore.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale name property of the domainFileStore {id} is null", domainFileStore.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale owner property of the domainFileStore {id} is null", domainFileStore.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the domainFileStore {id} is null", domainFileStore.Iid); + Logger.Trace("The non-nullabale thingPreference property of the domainFileStore {id} is null", domainFileStore.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index 842036389..59571a59a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement j { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement j { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement j { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + Logger.Trace("The non-nullabale name property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement j { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + Logger.Trace("The non-nullabale shortName property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement j { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index 06cf55214..e81c0408d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonEl { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + Logger.Trace("The non-nullabale name property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + Logger.Trace("The non-nullabale shortName property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index 91c5c81bb..5713aa4f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -123,7 +123,7 @@ public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the elementDefinition {id} is null", elementDefinition.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the elementDefinition {id} is null", elementDefinition.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the elementDefinition {id} is null", elementDefinition.Iid); + Logger.Trace("The non-nullabale name property of the elementDefinition {id} is null", elementDefinition.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonEl { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the elementDefinition {id} is null", elementDefinition.Iid); + Logger.Trace("The non-nullabale owner property of the elementDefinition {id} is null", elementDefinition.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the elementDefinition {id} is null", elementDefinition.Iid); + Logger.Trace("The non-nullabale shortName property of the elementDefinition {id} is null", elementDefinition.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the elementDefinition {id} is null", elementDefinition.Iid); + Logger.Trace("The non-nullabale thingPreference property of the elementDefinition {id} is null", elementDefinition.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index 8406d81e3..56f20ecfe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -91,7 +91,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(elementDefinitionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale elementDefinition property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale elementDefinition property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(interfaceEndProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale interfaceEnd property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale interfaceEnd property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale name property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale owner property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale shortName property of the elementUsage {id} is null", elementUsage.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the elementUsage {id} is null", elementUsage.Iid); + Logger.Trace("The non-nullabale thingPreference property of the elementUsage {id} is null", elementUsage.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index de0fbc233..7d7d3bea3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid); + Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement { if(valueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid); + Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement { if(vcardTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid); + Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index 3cd779c8f..4a27537a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale author property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale content property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(J { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index d49355db9..5c1508d82 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale author property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale content property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index f4f0ac12d..aeac88ff6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -80,7 +80,7 @@ public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonEle { if(engineeringModelSetupProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale engineeringModelSetup property of the engineeringModel {id} is null", engineeringModel.Iid); + Logger.Trace("The non-nullabale engineeringModelSetup property of the engineeringModel {id} is null", engineeringModel.Iid); } else { @@ -124,7 +124,7 @@ public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonEle { if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale lastModifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + Logger.Trace("The non-nullabale lastModifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); } else { @@ -152,7 +152,7 @@ public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); } else { @@ -164,7 +164,7 @@ public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the engineeringModel {id} is null", engineeringModel.Iid); + Logger.Trace("The non-nullabale thingPreference property of the engineeringModel {id} is null", engineeringModel.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index a0a05f287..1ce062d0a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -103,7 +103,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(engineeringModelIidProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale engineeringModelIid property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale engineeringModelIid property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(kindProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale kind property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale kind property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale name property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -207,7 +207,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale shortName property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -231,7 +231,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(studyPhaseProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale studyPhase property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale studyPhase property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index 6059bd7aa..d3837abd6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(allowMultiSelectProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale allowMultiSelect property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale allowMultiSelect property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale name property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index b0db8660e..5fa2053af 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonEleme { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + Logger.Trace("The non-nullabale name property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonEleme { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + Logger.Trace("The non-nullabale shortName property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + Logger.Trace("The non-nullabale thingPreference property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index 62d37fbb2..1f8ab3861 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + Logger.Trace("The non-nullabale thingPreference property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index 242f14aac..04c37e0ff 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -103,7 +103,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(externalModelNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale externalModelName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale externalModelName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(externalToolNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale externalToolName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale externalToolName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(externalToolVersionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale externalToolVersion property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale externalToolVersion property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale name property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale owner property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + Logger.Trace("The non-nullabale thingPreference property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index d7f52a5db..c07ae429c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -111,7 +111,7 @@ public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the file {id} is null", file.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the file {id} is null", file.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the file {id} is null", file.Iid); + Logger.Trace("The non-nullabale owner property of the file {id} is null", file.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the file {id} is null", file.Iid); + Logger.Trace("The non-nullabale thingPreference property of the file {id} is null", file.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index e7dc7b9bc..183011498 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -79,7 +79,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(contentHashProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale contentHash property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale contentHash property of the fileRevision {id} is null", fileRevision.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale createdOn property of the fileRevision {id} is null", fileRevision.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(creatorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale creator property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale creator property of the fileRevision {id} is null", fileRevision.Iid); } else { @@ -136,7 +136,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the fileRevision {id} is null", fileRevision.Iid); } else { @@ -148,7 +148,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale name property of the fileRevision {id} is null", fileRevision.Iid); } else { @@ -160,7 +160,7 @@ public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the fileRevision {id} is null", fileRevision.Iid); + Logger.Trace("The non-nullabale thingPreference property of the fileRevision {id} is null", fileRevision.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 15a415fa9..743c58341 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(extensionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale extension property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale extension property of the fileType {id} is null", fileType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the fileType {id} is null", fileType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the fileType {id} is null", fileType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale name property of the fileType {id} is null", fileType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale shortName property of the fileType {id} is null", fileType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the fileType {id} is null", fileType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the fileType {id} is null", fileType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index 61957f20b..a15b5febc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -79,7 +79,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale createdOn property of the folder {id} is null", folder.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(creatorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale creator property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale creator property of the folder {id} is null", folder.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the folder {id} is null", folder.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale name property of the folder {id} is null", folder.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale owner property of the folder {id} is null", folder.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the folder {id} is null", folder.Iid); + Logger.Trace("The non-nullabale thingPreference property of the folder {id} is null", folder.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 0b62a5f65..0f233c960 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the glossary {id} is null", glossary.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the glossary {id} is null", glossary.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the glossary {id} is null", glossary.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the glossary {id} is null", glossary.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the glossary {id} is null", glossary.Iid); + Logger.Trace("The non-nullabale name property of the glossary {id} is null", glossary.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the glossary {id} is null", glossary.Iid); + Logger.Trace("The non-nullabale shortName property of the glossary {id} is null", glossary.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the glossary {id} is null", glossary.Iid); + Logger.Trace("The non-nullabale thingPreference property of the glossary {id} is null", glossary.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index add132c03..be107d3a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the goal {id} is null", goal.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the goal {id} is null", goal.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the goal {id} is null", goal.Iid); + Logger.Trace("The non-nullabale name property of the goal {id} is null", goal.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the goal {id} is null", goal.Iid); + Logger.Trace("The non-nullabale shortName property of the goal {id} is null", goal.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the goal {id} is null", goal.Iid); + Logger.Trace("The non-nullabale thingPreference property of the goal {id} is null", goal.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index 2a47f983c..8b5405ded 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the hyperLink {id} is null", hyperLink.Iid); + Logger.Trace("The non-nullabale content property of the hyperLink {id} is null", hyperLink.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the hyperLink {id} is null", hyperLink.Iid); + Logger.Trace("The non-nullabale languageCode property of the hyperLink {id} is null", hyperLink.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the hyperLink {id} is null", hyperLink.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the hyperLink {id} is null", hyperLink.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the hyperLink {id} is null", hyperLink.Iid); + Logger.Trace("The non-nullabale thingPreference property of the hyperLink {id} is null", hyperLink.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { if(uriProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale uri property of the hyperLink {id} is null", hyperLink.Iid); + Logger.Trace("The non-nullabale uri property of the hyperLink {id} is null", hyperLink.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index dc573c684..bcbf34af9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonEle { if(externalIdProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale externalId property of the idCorrespondence {id} is null", idCorrespondence.Iid); + Logger.Trace("The non-nullabale externalId property of the idCorrespondence {id} is null", idCorrespondence.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonEle { if(internalThingProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale internalThing property of the idCorrespondence {id} is null", idCorrespondence.Iid); + Logger.Trace("The non-nullabale internalThing property of the idCorrespondence {id} is null", idCorrespondence.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the idCorrespondence {id} is null", idCorrespondence.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the idCorrespondence {id} is null", idCorrespondence.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the idCorrespondence {id} is null", idCorrespondence.Iid); + Logger.Trace("The non-nullabale thingPreference property of the idCorrespondence {id} is null", idCorrespondence.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index 2d8f77bb6..ad3bd6f91 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(J { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(J { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale parameterType property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(J { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + Logger.Trace("The non-nullabale thingPreference property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index ca2a5d4c8..0dd94eb40 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMaximumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale isMaximumInclusive property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMinimumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale isMinimumInclusive property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maximumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale maximumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minimumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale minimumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale name property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale negativeValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale negativeValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(numberSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale numberSet property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale numberSet property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale positiveValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale positiveValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale shortName property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the intervalScale {id} is null", intervalScale.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElemen { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the intervalScale {id} is null", intervalScale.Iid); + Logger.Trace("The non-nullabale unit property of the intervalScale {id} is null", intervalScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index ffc947b3f..c98d0a973 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { if(iterationSetupProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale iterationSetup property of the iteration {id} is null", iteration.Iid); + Logger.Trace("The non-nullabale iterationSetup property of the iteration {id} is null", iteration.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the iteration {id} is null", iteration.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the iteration {id} is null", iteration.Iid); } else { @@ -256,7 +256,7 @@ public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the iteration {id} is null", iteration.Iid); + Logger.Trace("The non-nullabale thingPreference property of the iteration {id} is null", iteration.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index c8e8447f2..74109e6a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale createdOn property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(descriptionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale description property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale description property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(isDeletedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeleted property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale isDeleted property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(iterationIidProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale iterationIid property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale iterationIid property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(iterationNumberProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale iterationNumber property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale iterationNumber property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the iterationSetup {id} is null", iterationSetup.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the iterationSetup {id} is null", iterationSetup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the iterationSetup {id} is null", iterationSetup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index 9cc1bca7b..5ec8444b6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(conversionFactorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale conversionFactor property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale conversionFactor property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale name property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(referenceUnitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referenceUnit property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale referenceUnit property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale shortName property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + Logger.Trace("The non-nullabale thingPreference property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index b36348479..797969a52 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement js { if(affectedItemIidProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale affectedItemIid property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + Logger.Trace("The non-nullabale affectedItemIid property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); } else { @@ -87,7 +87,7 @@ public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement js { if(changeDescriptionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale changeDescription property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + Logger.Trace("The non-nullabale changeDescription property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); } else { @@ -99,7 +99,7 @@ public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement js { if(changelogKindProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale changelogKind property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + Logger.Trace("The non-nullabale changelogKind property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + Logger.Trace("The non-nullabale thingPreference property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index e7e3ecfe7..8b3a5e2d6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -99,7 +99,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(exponentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale exponent property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale exponent property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(factorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale factor property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale factor property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMaximumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale isMaximumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMinimumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale isMinimumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(logarithmBaseProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale logarithmBase property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale logarithmBase property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maximumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale maximumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minimumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale minimumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale name property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale negativeValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale negativeValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(numberSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale numberSet property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale numberSet property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale positiveValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale positiveValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -271,7 +271,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(referenceQuantityKindProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referenceQuantityKind property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale referenceQuantityKind property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -291,7 +291,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale shortName property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -303,7 +303,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { @@ -315,7 +315,7 @@ public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonEle { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the logarithmicScale {id} is null", logarithmicScale.Iid); + Logger.Trace("The non-nullabale unit property of the logarithmicScale {id} is null", logarithmicScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index dbb65b2f6..e9ccb89b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement { if(dependentScaleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale dependentScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + Logger.Trace("The non-nullabale dependentScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement { if(referenceScaleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referenceScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + Logger.Trace("The non-nullabale referenceScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index 46817fdaf..b094b4c33 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -103,7 +103,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale content property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale createdOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale languageCode property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(levelProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale level property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale level property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the modelLogEntry {id} is null", modelLogEntry.Iid); + Logger.Trace("The non-nullabale thingPreference property of the modelLogEntry {id} is null", modelLogEntry.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 5490153a5..30bd10fae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -152,7 +152,7 @@ public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); } else { @@ -164,7 +164,7 @@ public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale name property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); } else { @@ -220,7 +220,7 @@ public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale shortName property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); } else { @@ -232,7 +232,7 @@ public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale thingPreference property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index 9f834b6c7..0be75fb8f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the modellingThingReference {id} is null", modellingThingReference.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the modellingThingReference {id} is null", modellingThingReference.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement { if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referencedRevisionNumber property of the modellingThingReference {id} is null", modellingThingReference.Iid); + Logger.Trace("The non-nullabale referencedRevisionNumber property of the modellingThingReference {id} is null", modellingThingReference.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement { if(referencedThingProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referencedThing property of the modellingThingReference {id} is null", modellingThingReference.Iid); + Logger.Trace("The non-nullabale referencedThing property of the modellingThingReference {id} is null", modellingThingReference.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the modellingThingReference {id} is null", modellingThingReference.Iid); + Logger.Trace("The non-nullabale thingPreference property of the modellingThingReference {id} is null", modellingThingReference.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index 53831176a..bb84b2ff0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -91,7 +91,7 @@ public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the multiRelationship {id} is null", multiRelationship.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationship {id} is null", multiRelationship.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the multiRelationship {id} is null", multiRelationship.Iid); + Logger.Trace("The non-nullabale name property of the multiRelationship {id} is null", multiRelationship.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonEl { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the multiRelationship {id} is null", multiRelationship.Iid); + Logger.Trace("The non-nullabale owner property of the multiRelationship {id} is null", multiRelationship.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the multiRelationship {id} is null", multiRelationship.Iid); + Logger.Trace("The non-nullabale thingPreference property of the multiRelationship {id} is null", multiRelationship.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index 8c980774c..f416dd9eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(maxRelatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maxRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale maxRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(minRelatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale minRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale name property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale relationshipCategory property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale relationshipCategory property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale shortName property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + Logger.Trace("The non-nullabale thingPreference property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index afc4b90e4..faf8c2fca 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElem { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the naturalLanguage {id} is null", naturalLanguage.Iid); + Logger.Trace("The non-nullabale languageCode property of the naturalLanguage {id} is null", naturalLanguage.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the naturalLanguage {id} is null", naturalLanguage.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the naturalLanguage {id} is null", naturalLanguage.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElem { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the naturalLanguage {id} is null", naturalLanguage.Iid); + Logger.Trace("The non-nullabale name property of the naturalLanguage {id} is null", naturalLanguage.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElem { if(nativeNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale nativeName property of the naturalLanguage {id} is null", naturalLanguage.Iid); + Logger.Trace("The non-nullabale nativeName property of the naturalLanguage {id} is null", naturalLanguage.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the naturalLanguage {id} is null", naturalLanguage.Iid); + Logger.Trace("The non-nullabale thingPreference property of the naturalLanguage {id} is null", naturalLanguage.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index d7eb62e54..267e809bc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -88,7 +88,7 @@ public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElemen { if(isVolatileProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isVolatile property of the nestedElement {id} is null", nestedElement.Iid); + Logger.Trace("The non-nullabale isVolatile property of the nestedElement {id} is null", nestedElement.Iid); } else { @@ -100,7 +100,7 @@ public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the nestedElement {id} is null", nestedElement.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the nestedElement {id} is null", nestedElement.Iid); } else { @@ -120,7 +120,7 @@ public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElemen { if(rootElementProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale rootElement property of the nestedElement {id} is null", nestedElement.Iid); + Logger.Trace("The non-nullabale rootElement property of the nestedElement {id} is null", nestedElement.Iid); } else { @@ -132,7 +132,7 @@ public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the nestedElement {id} is null", nestedElement.Iid); + Logger.Trace("The non-nullabale thingPreference property of the nestedElement {id} is null", nestedElement.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index 30c147689..2598bdb4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -79,7 +79,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(actualValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale actualValue property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale actualValue property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(associatedParameterProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale associatedParameter property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale associatedParameter property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(formulaProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale formula property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale formula property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(isVolatileProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isVolatile property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale isVolatile property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale owner property of the nestedParameter {id} is null", nestedParameter.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the nestedParameter {id} is null", nestedParameter.Iid); + Logger.Trace("The non-nullabale thingPreference property of the nestedParameter {id} is null", nestedParameter.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index 185f66df2..ced4ee8de 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the notExpression {id} is null", notExpression.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the notExpression {id} is null", notExpression.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElemen { if(termProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale term property of the notExpression {id} is null", notExpression.Iid); + Logger.Trace("The non-nullabale term property of the notExpression {id} is null", notExpression.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the notExpression {id} is null", notExpression.Iid); + Logger.Trace("The non-nullabale thingPreference property of the notExpression {id} is null", notExpression.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index 72dd27d06..37f545056 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the option {id} is null", option.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the option {id} is null", option.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the option {id} is null", option.Iid); + Logger.Trace("The non-nullabale name property of the option {id} is null", option.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the option {id} is null", option.Iid); + Logger.Trace("The non-nullabale shortName property of the option {id} is null", option.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the option {id} is null", option.Iid); + Logger.Trace("The non-nullabale thingPreference property of the option {id} is null", option.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index 596b989ac..a6c5e29a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.OrExpression FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the orExpression {id} is null", orExpression.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the orExpression {id} is null", orExpression.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.OrExpression FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the orExpression {id} is null", orExpression.Iid); + Logger.Trace("The non-nullabale thingPreference property of the orExpression {id} is null", orExpression.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index fc3cb2148..28e6d26b5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMaximumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale isMaximumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMinimumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale isMinimumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maximumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minimumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale name property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale negativeValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale negativeValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(numberSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale numberSet property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale numberSet property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale positiveValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale positiveValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale shortName property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale unit property of the ordinalScale {id} is null", ordinalScale.Iid); } else { @@ -271,7 +271,7 @@ public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement { if(useShortNameValuesProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale useShortNameValues property of the ordinalScale {id} is null", ordinalScale.Iid); + Logger.Trace("The non-nullabale useShortNameValues property of the ordinalScale {id} is null", ordinalScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index 2e50a992b..2212bddfd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the organization {id} is null", organization.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the organization {id} is null", organization.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the organization {id} is null", organization.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the organization {id} is null", organization.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the organization {id} is null", organization.Iid); + Logger.Trace("The non-nullabale name property of the organization {id} is null", organization.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the organization {id} is null", organization.Iid); + Logger.Trace("The non-nullabale shortName property of the organization {id} is null", organization.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the organization {id} is null", organization.Iid); + Logger.Trace("The non-nullabale thingPreference property of the organization {id} is null", organization.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index 560cbfa06..a477bc0d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElemen { if(organizationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale organization property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + Logger.Trace("The non-nullabale organization property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + Logger.Trace("The non-nullabale thingPreference property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index a0c000fb4..c4c58cb19 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -143,7 +143,7 @@ public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { if(fontNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale fontName property of the ownedStyle {id} is null", ownedStyle.Iid); + Logger.Trace("The non-nullabale fontName property of the ownedStyle {id} is null", ownedStyle.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the ownedStyle {id} is null", ownedStyle.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the ownedStyle {id} is null", ownedStyle.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the ownedStyle {id} is null", ownedStyle.Iid); + Logger.Trace("The non-nullabale name property of the ownedStyle {id} is null", ownedStyle.Iid); } else { @@ -251,7 +251,7 @@ public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the ownedStyle {id} is null", ownedStyle.Iid); + Logger.Trace("The non-nullabale thingPreference property of the ownedStyle {id} is null", ownedStyle.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index 80415d1e6..8e660d4c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale createdOn property of the page {id} is null", page.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the page {id} is null", page.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale name property of the page {id} is null", page.Iid); } else { @@ -132,7 +132,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale owner property of the page {id} is null", page.Iid); } else { @@ -144,7 +144,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale shortName property of the page {id} is null", page.Iid); } else { @@ -156,7 +156,7 @@ public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the page {id} is null", page.Iid); + Logger.Trace("The non-nullabale thingPreference property of the page {id} is null", page.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 97c0a8da7..464ab4ccd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterGroup {id} is null", parameterGroup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterGroup {id} is null", parameterGroup.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonEleme { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the parameterGroup {id} is null", parameterGroup.Iid); + Logger.Trace("The non-nullabale name property of the parameterGroup {id} is null", parameterGroup.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterGroup {id} is null", parameterGroup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterGroup {id} is null", parameterGroup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index 1c54ce876..581450bb9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterOverride {id} is null", parameterOverride.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverride {id} is null", parameterOverride.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonEl { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the parameterOverride {id} is null", parameterOverride.Iid); + Logger.Trace("The non-nullabale owner property of the parameterOverride {id} is null", parameterOverride.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonEl { if(parameterProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameter property of the parameterOverride {id} is null", parameterOverride.Iid); + Logger.Trace("The non-nullabale parameter property of the parameterOverride {id} is null", parameterOverride.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterOverride {id} is null", parameterOverride.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterOverride {id} is null", parameterOverride.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index 431d85fbb..24b52b639 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -96,7 +96,7 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); } else { @@ -108,7 +108,7 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen { if(parameterValueSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterValueSet property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + Logger.Trace("The non-nullabale parameterValueSet property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); } else { @@ -128,7 +128,7 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); } else { @@ -140,7 +140,7 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen { if(valueSwitchProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale valueSwitch property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + Logger.Trace("The non-nullabale valueSwitch property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index f122ceab5..8c6f0d9a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(allowDifferentOwnerOfOverrideProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale allowDifferentOwnerOfOverride property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale allowDifferentOwnerOfOverride property of the parameter {id} is null", parameter.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(expectsOverrideProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale expectsOverride property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale expectsOverride property of the parameter {id} is null", parameter.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(isOptionDependentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isOptionDependent property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale isOptionDependent property of the parameter {id} is null", parameter.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameter {id} is null", parameter.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale owner property of the parameter {id} is null", parameter.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale parameterType property of the parameter {id} is null", parameter.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameter {id} is null", parameter.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameter {id} is null", parameter.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index 98f8d7966..7ed54fe41 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterSubscription {id} is null", parameterSubscription.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscription {id} is null", parameterSubscription.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement js { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the parameterSubscription {id} is null", parameterSubscription.Iid); + Logger.Trace("The non-nullabale owner property of the parameterSubscription {id} is null", parameterSubscription.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterSubscription {id} is null", parameterSubscription.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscription {id} is null", parameterSubscription.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index e96359edd..07a280703 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -87,7 +87,7 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); } else { @@ -99,7 +99,7 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl { if(subscribedValueSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale subscribedValueSet property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + Logger.Trace("The non-nullabale subscribedValueSet property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); } else { @@ -111,7 +111,7 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl { if(valueSwitchProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale valueSwitch property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + Logger.Trace("The non-nullabale valueSwitch property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index 46dd2f162..8223b6a2f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement j { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement j { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + Logger.Trace("The non-nullabale parameterType property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement j { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + Logger.Trace("The non-nullabale shortName property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement j { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index c90526ee6..045a68a19 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterValueSet {id} is null", parameterValueSet.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterValueSet {id} is null", parameterValueSet.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterValueSet {id} is null", parameterValueSet.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterValueSet {id} is null", parameterValueSet.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl { if(valueSwitchProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale valueSwitch property of the parameterValueSet {id} is null", parameterValueSet.Iid); + Logger.Trace("The non-nullabale valueSwitch property of the parameterValueSet {id} is null", parameterValueSet.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index 8e2827fdf..dd07a654d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(categoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale category property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale category property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale name property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale shortName property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index f2d354a87..0a2167b1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -91,7 +91,7 @@ public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the parametricConstraint {id} is null", parametricConstraint.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the parametricConstraint {id} is null", parametricConstraint.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the parametricConstraint {id} is null", parametricConstraint.Iid); + Logger.Trace("The non-nullabale thingPreference property of the parametricConstraint {id} is null", parametricConstraint.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index fb6c00c08..c2339f659 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement js { if(accessRightProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale accessRight property of the participantPermission {id} is null", participantPermission.Iid); + Logger.Trace("The non-nullabale accessRight property of the participantPermission {id} is null", participantPermission.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement js { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the participantPermission {id} is null", participantPermission.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the participantPermission {id} is null", participantPermission.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the participantPermission {id} is null", participantPermission.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the participantPermission {id} is null", participantPermission.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement js { if(objectClassProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale objectClass property of the participantPermission {id} is null", participantPermission.Iid); + Logger.Trace("The non-nullabale objectClass property of the participantPermission {id} is null", participantPermission.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the participantPermission {id} is null", participantPermission.Iid); + Logger.Trace("The non-nullabale thingPreference property of the participantPermission {id} is null", participantPermission.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index 0748cf6a6..ae2e97390 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -91,7 +91,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(isActiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isActive property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale isActive property of the participant {id} is null", participant.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the participant {id} is null", participant.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(personProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale person property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale person property of the participant {id} is null", participant.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(roleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale role property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale role property of the participant {id} is null", participant.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(selectedDomainProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale selectedDomain property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale selectedDomain property of the participant {id} is null", participant.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the participant {id} is null", participant.Iid); + Logger.Trace("The non-nullabale thingPreference property of the participant {id} is null", participant.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index d9f821a41..dc98a81ec 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElem { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the participantRole {id} is null", participantRole.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the participantRole {id} is null", participantRole.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the participantRole {id} is null", participantRole.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the participantRole {id} is null", participantRole.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElem { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the participantRole {id} is null", participantRole.Iid); + Logger.Trace("The non-nullabale name property of the participantRole {id} is null", participantRole.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElem { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the participantRole {id} is null", participantRole.Iid); + Logger.Trace("The non-nullabale shortName property of the participantRole {id} is null", participantRole.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the participantRole {id} is null", participantRole.Iid); + Logger.Trace("The non-nullabale thingPreference property of the participantRole {id} is null", participantRole.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index e9bf0582a..4319167f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonEle { if(accessRightProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale accessRight property of the personPermission {id} is null", personPermission.Iid); + Logger.Trace("The non-nullabale accessRight property of the personPermission {id} is null", personPermission.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonEle { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the personPermission {id} is null", personPermission.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the personPermission {id} is null", personPermission.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the personPermission {id} is null", personPermission.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the personPermission {id} is null", personPermission.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonEle { if(objectClassProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale objectClass property of the personPermission {id} is null", personPermission.Iid); + Logger.Trace("The non-nullabale objectClass property of the personPermission {id} is null", personPermission.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the personPermission {id} is null", personPermission.Iid); + Logger.Trace("The non-nullabale thingPreference property of the personPermission {id} is null", personPermission.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index e5c3c1b4b..286a55dd9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(givenNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale givenName property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale givenName property of the person {id} is null", person.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(isActiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isActive property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale isActive property of the person {id} is null", person.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the person {id} is null", person.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the person {id} is null", person.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(organizationalUnitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale organizationalUnit property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale organizationalUnit property of the person {id} is null", person.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(passwordProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale password property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale password property of the person {id} is null", person.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale shortName property of the person {id} is null", person.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(surnameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale surname property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale surname property of the person {id} is null", person.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the person {id} is null", person.Iid); + Logger.Trace("The non-nullabale thingPreference property of the person {id} is null", person.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index 0b6afb333..41661b8bf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the personRole {id} is null", personRole.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the personRole {id} is null", personRole.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the personRole {id} is null", personRole.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the personRole {id} is null", personRole.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the personRole {id} is null", personRole.Iid); + Logger.Trace("The non-nullabale name property of the personRole {id} is null", personRole.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the personRole {id} is null", personRole.Iid); + Logger.Trace("The non-nullabale shortName property of the personRole {id} is null", personRole.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the personRole {id} is null", personRole.Iid); + Logger.Trace("The non-nullabale thingPreference property of the personRole {id} is null", personRole.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index fb36ae541..cbe6fc2ac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the point {id} is null", point.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the point {id} is null", point.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the point {id} is null", point.Iid); + Logger.Trace("The non-nullabale name property of the point {id} is null", point.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the point {id} is null", point.Iid); + Logger.Trace("The non-nullabale thingPreference property of the point {id} is null", point.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { if(xProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale x property of the point {id} is null", point.Iid); + Logger.Trace("The non-nullabale x property of the point {id} is null", point.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { if(yProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale y property of the point {id} is null", point.Iid); + Logger.Trace("The non-nullabale y property of the point {id} is null", point.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index 3f9da6d33..e512c0dcb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -127,7 +127,7 @@ public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + Logger.Trace("The non-nullabale name property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + Logger.Trace("The non-nullabale owner property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); } else { @@ -168,7 +168,7 @@ public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + Logger.Trace("The non-nullabale shortName property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); } else { @@ -180,7 +180,7 @@ public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index 03d5087d8..11535ae6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement json { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement json { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + Logger.Trace("The non-nullabale name property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement json { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + Logger.Trace("The non-nullabale shortName property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement json { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index e5864560b..839c14026 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the prefixedUnit {id} is null", prefixedUnit.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the prefixedUnit {id} is null", prefixedUnit.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the prefixedUnit {id} is null", prefixedUnit.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the prefixedUnit {id} is null", prefixedUnit.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement { if(prefixProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale prefix property of the prefixedUnit {id} is null", prefixedUnit.Iid); + Logger.Trace("The non-nullabale prefix property of the prefixedUnit {id} is null", prefixedUnit.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement { if(referenceUnitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referenceUnit property of the prefixedUnit {id} is null", prefixedUnit.Iid); + Logger.Trace("The non-nullabale referenceUnit property of the prefixedUnit {id} is null", prefixedUnit.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the prefixedUnit {id} is null", prefixedUnit.Iid); + Logger.Trace("The non-nullabale thingPreference property of the prefixedUnit {id} is null", prefixedUnit.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index 8928ca912..d72f4da56 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the publication {id} is null", publication.Iid); + Logger.Trace("The non-nullabale createdOn property of the publication {id} is null", publication.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the publication {id} is null", publication.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the publication {id} is null", publication.Iid); } else { @@ -123,7 +123,7 @@ public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the publication {id} is null", publication.Iid); + Logger.Trace("The non-nullabale thingPreference property of the publication {id} is null", publication.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index ce4a93914..089263793 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonE { if(exponentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale exponent property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + Logger.Trace("The non-nullabale exponent property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonE { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonE { if(quantityKindProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale quantityKind property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + Logger.Trace("The non-nullabale quantityKind property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonE { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + Logger.Trace("The non-nullabale thingPreference property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 3f4d494dc..7cf7008c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMaximumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale isMaximumInclusive property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isMinimumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale isMinimumInclusive property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maximumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minimumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale name property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale negativeValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale negativeValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(numberSetProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale numberSet property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale numberSet property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale positiveValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale positiveValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale shortName property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale thingPreference property of the ratioScale {id} is null", ratioScale.Iid); } else { @@ -259,7 +259,7 @@ public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the ratioScale {id} is null", ratioScale.Iid); + Logger.Trace("The non-nullabale unit property of the ratioScale {id} is null", ratioScale.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index 4590d1a68..b32c08056 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale author property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(languageProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale language property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale language property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale name property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale shortName property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -223,7 +223,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale thingPreference property of the referenceSource {id} is null", referenceSource.Iid); } else { @@ -247,7 +247,7 @@ public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElem { if(versionIdentifierProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale versionIdentifier property of the referenceSource {id} is null", referenceSource.Iid); + Logger.Trace("The non-nullabale versionIdentifier property of the referenceSource {id} is null", referenceSource.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index c965a9f79..fc0f56672 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(maxReferencedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale maxReferenced property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale maxReferenced property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(minReferencedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale minReferenced property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale minReferenced property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale name property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(referencingCategoryProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referencingCategory property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale referencingCategory property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale shortName property of the referencerRule {id} is null", referencerRule.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the referencerRule {id} is null", referencerRule.Iid); + Logger.Trace("The non-nullabale thingPreference property of the referencerRule {id} is null", referencerRule.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index 77c392685..ca549cad2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the relationalExpression {id} is null", relationalExpression.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the relationalExpression {id} is null", relationalExpression.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the relationalExpression {id} is null", relationalExpression.Iid); + Logger.Trace("The non-nullabale parameterType property of the relationalExpression {id} is null", relationalExpression.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso { if(relationalOperatorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale relationalOperator property of the relationalExpression {id} is null", relationalExpression.Iid); + Logger.Trace("The non-nullabale relationalOperator property of the relationalExpression {id} is null", relationalExpression.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the relationalExpression {id} is null", relationalExpression.Iid); + Logger.Trace("The non-nullabale thingPreference property of the relationalExpression {id} is null", relationalExpression.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index 8437ea8ad..65c5f9236 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonEleme { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + Logger.Trace("The non-nullabale parameterType property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + Logger.Trace("The non-nullabale thingPreference property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index f4bd88419..e3f87ec31 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale author property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale classification property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale content property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale createdOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale languageCode property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale owner property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale shortName property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -231,7 +231,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale status property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement json { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the requestForDeviation {id} is null", requestForDeviation.Iid); + Logger.Trace("The non-nullabale title property of the requestForDeviation {id} is null", requestForDeviation.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index e957a5040..a56451c6b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale author property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale classification property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale content property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale createdOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale languageCode property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale owner property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale shortName property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -231,7 +231,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale status property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -243,7 +243,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonEle { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the requestForWaiver {id} is null", requestForWaiver.Iid); + Logger.Trace("The non-nullabale title property of the requestForWaiver {id} is null", requestForWaiver.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index 5fde343c5..2d7adbcde 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the requirement {id} is null", requirement.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requirement {id} is null", requirement.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale name property of the requirement {id} is null", requirement.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale owner property of the requirement {id} is null", requirement.Iid); } else { @@ -188,7 +188,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale shortName property of the requirement {id} is null", requirement.Iid); } else { @@ -200,7 +200,7 @@ public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requirement {id} is null", requirement.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requirement {id} is null", requirement.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index 634d5fbf4..4fbdf07aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject( { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject( { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + Logger.Trace("The non-nullabale parameterType property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject( { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index b6e4218e1..1439abe7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -123,7 +123,7 @@ public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requirementsGroup {id} is null", requirementsGroup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requirementsGroup {id} is null", requirementsGroup.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the requirementsGroup {id} is null", requirementsGroup.Iid); + Logger.Trace("The non-nullabale name property of the requirementsGroup {id} is null", requirementsGroup.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonEl { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the requirementsGroup {id} is null", requirementsGroup.Iid); + Logger.Trace("The non-nullabale owner property of the requirementsGroup {id} is null", requirementsGroup.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the requirementsGroup {id} is null", requirementsGroup.Iid); + Logger.Trace("The non-nullabale shortName property of the requirementsGroup {id} is null", requirementsGroup.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requirementsGroup {id} is null", requirementsGroup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requirementsGroup {id} is null", requirementsGroup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index 423026111..c6cb5b0c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -123,7 +123,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { @@ -147,7 +147,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale name property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale owner property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale shortName property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { @@ -199,7 +199,7 @@ public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + Logger.Trace("The non-nullabale thingPreference property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index ad2873076..163e50852 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale author property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(classificationProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale classification property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale classification property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale content property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale createdOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale languageCode property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -179,7 +179,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale owner property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -211,7 +211,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale shortName property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -239,7 +239,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale status property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -251,7 +251,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale thingPreference property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { @@ -263,7 +263,7 @@ public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement js { if(titleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale title property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + Logger.Trace("The non-nullabale title property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index 428b4121e..2d970f525 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jso { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + Logger.Trace("The non-nullabale name property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jso { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + Logger.Trace("The non-nullabale owner property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); } else { @@ -148,7 +148,7 @@ public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jso { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + Logger.Trace("The non-nullabale shortName property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); } else { @@ -160,7 +160,7 @@ public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + Logger.Trace("The non-nullabale thingPreference property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index 45199c0de..45a79e1df 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElemen { if(descriptionProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale description property of the ruleViolation {id} is null", ruleViolation.Iid); + Logger.Trace("The non-nullabale description property of the ruleViolation {id} is null", ruleViolation.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the ruleViolation {id} is null", ruleViolation.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the ruleViolation {id} is null", ruleViolation.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the ruleViolation {id} is null", ruleViolation.Iid); + Logger.Trace("The non-nullabale thingPreference property of the ruleViolation {id} is null", ruleViolation.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index c1d7c617e..946660f7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -141,7 +141,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { @@ -153,7 +153,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { @@ -165,7 +165,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale name property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { @@ -177,7 +177,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { @@ -189,7 +189,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { @@ -201,7 +201,7 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index fde46eb30..4b915e1f5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElem { if(scaleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale scale property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + Logger.Trace("The non-nullabale scale property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + Logger.Trace("The non-nullabale thingPreference property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElem { if(valueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale value property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + Logger.Trace("The non-nullabale value property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index 3979cde6d..819ab270f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jso { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + Logger.Trace("The non-nullabale name property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jso { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + Logger.Trace("The non-nullabale shortName property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + Logger.Trace("The non-nullabale thingPreference property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jso { if(valueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale value property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + Logger.Trace("The non-nullabale value property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index 9dbef1bc9..9fc4e315c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale createdOn property of the section {id} is null", section.Iid); } else { @@ -103,7 +103,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the section {id} is null", section.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale name property of the section {id} is null", section.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale owner property of the section {id} is null", section.Iid); } else { @@ -144,7 +144,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale shortName property of the section {id} is null", section.Iid); } else { @@ -156,7 +156,7 @@ public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the section {id} is null", section.Iid); + Logger.Trace("The non-nullabale thingPreference property of the section {id} is null", section.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index 3508f96dd..cfa19318a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -143,7 +143,7 @@ public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { if(fontNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale fontName property of the sharedStyle {id} is null", sharedStyle.Iid); + Logger.Trace("The non-nullabale fontName property of the sharedStyle {id} is null", sharedStyle.Iid); } else { @@ -191,7 +191,7 @@ public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the sharedStyle {id} is null", sharedStyle.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the sharedStyle {id} is null", sharedStyle.Iid); } else { @@ -203,7 +203,7 @@ public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the sharedStyle {id} is null", sharedStyle.Iid); + Logger.Trace("The non-nullabale name property of the sharedStyle {id} is null", sharedStyle.Iid); } else { @@ -251,7 +251,7 @@ public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the sharedStyle {id} is null", sharedStyle.Iid); + Logger.Trace("The non-nullabale thingPreference property of the sharedStyle {id} is null", sharedStyle.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index bcc744308..fa8f3b82c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jso { if(parameterTypeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale parameterType property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + Logger.Trace("The non-nullabale parameterType property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + Logger.Trace("The non-nullabale thingPreference property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index b7b864b58..d3cf8a6e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(defaultScaleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale defaultScale property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale defaultScale property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale name property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale quantityDimensionSymbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -183,7 +183,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale shortName property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -195,7 +195,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale symbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { @@ -207,7 +207,7 @@ public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonE { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + Logger.Trace("The non-nullabale thingPreference property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index 53ac8fc41..2e4812866 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the simpleUnit {id} is null", simpleUnit.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the simpleUnit {id} is null", simpleUnit.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the simpleUnit {id} is null", simpleUnit.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the simpleUnit {id} is null", simpleUnit.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the simpleUnit {id} is null", simpleUnit.Iid); + Logger.Trace("The non-nullabale name property of the simpleUnit {id} is null", simpleUnit.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the simpleUnit {id} is null", simpleUnit.Iid); + Logger.Trace("The non-nullabale shortName property of the simpleUnit {id} is null", simpleUnit.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the simpleUnit {id} is null", simpleUnit.Iid); + Logger.Trace("The non-nullabale thingPreference property of the simpleUnit {id} is null", simpleUnit.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index 2d60b0f17..68d422c8b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale author property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale content property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale primaryAnnotatedThing property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale primaryAnnotatedThing property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 71d006535..459029ada 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale author property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale content property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(Json { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index 57db9f6e4..6c3350b55 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale createdOn property of the siteDirectory {id} is null", siteDirectory.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale lastModifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale lastModifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); } else { @@ -171,7 +171,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); } else { @@ -183,7 +183,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale name property of the siteDirectory {id} is null", siteDirectory.Iid); } else { @@ -235,7 +235,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale shortName property of the siteDirectory {id} is null", siteDirectory.Iid); } else { @@ -255,7 +255,7 @@ public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElemen { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteDirectory {id} is null", siteDirectory.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteDirectory {id} is null", siteDirectory.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index 28946bf18..11ccc900c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElem { if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referencedRevisionNumber property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + Logger.Trace("The non-nullabale referencedRevisionNumber property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElem { if(referencedThingProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale referencedThing property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + Logger.Trace("The non-nullabale referencedThing property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index 2e9c5fabe..a3c5db285 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -103,7 +103,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale content property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale createdOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale languageCode property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(levelProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale level property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale level property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { @@ -187,7 +187,7 @@ public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteLogEntry {id} is null", siteLogEntry.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteLogEntry {id} is null", siteLogEntry.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index fc7c9afdf..dd212ecb4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -152,7 +152,7 @@ public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); } else { @@ -164,7 +164,7 @@ public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); } else { @@ -176,7 +176,7 @@ public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale name property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); } else { @@ -232,7 +232,7 @@ public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale shortName property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); } else { @@ -244,7 +244,7 @@ public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + Logger.Trace("The non-nullabale thingPreference property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index 37940cf95..9d427ee8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -67,7 +67,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(authorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale author property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale author property of the solution {id} is null", solution.Iid); } else { @@ -79,7 +79,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale content property of the solution {id} is null", solution.Iid); } else { @@ -91,7 +91,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale createdOn property of the solution {id} is null", solution.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale languageCode property of the solution {id} is null", solution.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the solution {id} is null", solution.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale owner property of the solution {id} is null", solution.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the solution {id} is null", solution.Iid); + Logger.Trace("The non-nullabale thingPreference property of the solution {id} is null", solution.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index dc593f909..8c7076c26 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(defaultScaleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale defaultScale property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale defaultScale property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(generalProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale general property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale general property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale name property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -183,7 +183,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale quantityDimensionSymbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -195,7 +195,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale shortName property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -207,7 +207,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale symbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { @@ -219,7 +219,7 @@ public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + Logger.Trace("The non-nullabale thingPreference property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index 2a3d0bc4f..5795d07a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -123,7 +123,7 @@ public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement json { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); } else { @@ -135,7 +135,7 @@ public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement json { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + Logger.Trace("The non-nullabale name property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement json { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + Logger.Trace("The non-nullabale shortName property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); } else { @@ -183,7 +183,7 @@ public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement json { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index cf611c630..9863c5486 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index 36e471fef..2a4191a5a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the stakeholder {id} is null", stakeholder.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the stakeholder {id} is null", stakeholder.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the stakeholder {id} is null", stakeholder.Iid); + Logger.Trace("The non-nullabale name property of the stakeholder {id} is null", stakeholder.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the stakeholder {id} is null", stakeholder.Iid); + Logger.Trace("The non-nullabale shortName property of the stakeholder {id} is null", stakeholder.Iid); } else { @@ -159,7 +159,7 @@ public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the stakeholder {id} is null", stakeholder.Iid); + Logger.Trace("The non-nullabale thingPreference property of the stakeholder {id} is null", stakeholder.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index be7fa1876..88d7c6a47 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonEle { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the stakeholderValue {id} is null", stakeholderValue.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the stakeholderValue {id} is null", stakeholderValue.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonEle { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the stakeholderValue {id} is null", stakeholderValue.Iid); + Logger.Trace("The non-nullabale name property of the stakeholderValue {id} is null", stakeholderValue.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonEle { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the stakeholderValue {id} is null", stakeholderValue.Iid); + Logger.Trace("The non-nullabale shortName property of the stakeholderValue {id} is null", stakeholderValue.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonEle { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the stakeholderValue {id} is null", stakeholderValue.Iid); + Logger.Trace("The non-nullabale thingPreference property of the stakeholderValue {id} is null", stakeholderValue.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 775ad6bde..95b744ffe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElem { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElem { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid); + Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElem { if(valueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid); + Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index a2a92daa0..ed17540c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -107,7 +107,7 @@ public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the term {id} is null", term.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the term {id} is null", term.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the term {id} is null", term.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the term {id} is null", term.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the term {id} is null", term.Iid); + Logger.Trace("The non-nullabale name property of the term {id} is null", term.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the term {id} is null", term.Iid); + Logger.Trace("The non-nullabale shortName property of the term {id} is null", term.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the term {id} is null", term.Iid); + Logger.Trace("The non-nullabale thingPreference property of the term {id} is null", term.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index c88507401..ae9fbb9d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the textParameterType {id} is null", textParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the textParameterType {id} is null", textParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale name property of the textParameterType {id} is null", textParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the textParameterType {id} is null", textParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the textParameterType {id} is null", textParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonEl { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the textParameterType {id} is null", textParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the textParameterType {id} is null", textParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index 490706e1d..14391575e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(contentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale content property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale content property of the textualNote {id} is null", textualNote.Iid); } else { @@ -87,7 +87,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(createdOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale createdOn property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale createdOn property of the textualNote {id} is null", textualNote.Iid); } else { @@ -115,7 +115,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(languageCodeProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale languageCode property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale languageCode property of the textualNote {id} is null", textualNote.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the textualNote {id} is null", textualNote.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale name property of the textualNote {id} is null", textualNote.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(ownerProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale owner property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale owner property of the textualNote {id} is null", textualNote.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale shortName property of the textualNote {id} is null", textualNote.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the textualNote {id} is null", textualNote.Iid); + Logger.Trace("The non-nullabale thingPreference property of the textualNote {id} is null", textualNote.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index 218e355c7..1cea57539 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale name property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale shortName property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { @@ -163,7 +163,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(symbolProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale symbol property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale symbol property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { @@ -175,7 +175,7 @@ public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement j { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + Logger.Trace("The non-nullabale thingPreference property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index 147ac291c..217ebd135 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { if(exponentProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale exponent property of the unitFactor {id} is null", unitFactor.Iid); + Logger.Trace("The non-nullabale exponent property of the unitFactor {id} is null", unitFactor.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the unitFactor {id} is null", unitFactor.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the unitFactor {id} is null", unitFactor.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the unitFactor {id} is null", unitFactor.Iid); + Logger.Trace("The non-nullabale thingPreference property of the unitFactor {id} is null", unitFactor.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { if(unitProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale unit property of the unitFactor {id} is null", unitFactor.Iid); + Logger.Trace("The non-nullabale unit property of the unitFactor {id} is null", unitFactor.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index 9abd0988b..7871cf4e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -75,7 +75,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(conversionFactorProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale conversionFactor property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale conversionFactor property of the unitPrefix {id} is null", unitPrefix.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isDeprecated property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale isDeprecated property of the unitPrefix {id} is null", unitPrefix.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the unitPrefix {id} is null", unitPrefix.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale name property of the unitPrefix {id} is null", unitPrefix.Iid); } else { @@ -155,7 +155,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale shortName property of the unitPrefix {id} is null", unitPrefix.Iid); } else { @@ -167,7 +167,7 @@ public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the unitPrefix {id} is null", unitPrefix.Iid); + Logger.Trace("The non-nullabale thingPreference property of the unitPrefix {id} is null", unitPrefix.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index 5a3ec842c..20bea1856 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -83,7 +83,7 @@ public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonEleme { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the userPreference {id} is null", userPreference.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the userPreference {id} is null", userPreference.Iid); } else { @@ -95,7 +95,7 @@ public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonEleme { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the userPreference {id} is null", userPreference.Iid); + Logger.Trace("The non-nullabale shortName property of the userPreference {id} is null", userPreference.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonEleme { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the userPreference {id} is null", userPreference.Iid); + Logger.Trace("The non-nullabale thingPreference property of the userPreference {id} is null", userPreference.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonEleme { if(valueProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale value property of the userPreference {id} is null", userPreference.Iid); + Logger.Trace("The non-nullabale value property of the userPreference {id} is null", userPreference.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index 55801be0e..d5edbfa43 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -95,7 +95,7 @@ public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jso { if(isActiveProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale isActive property of the userRuleVerification {id} is null", userRuleVerification.Iid); + Logger.Trace("The non-nullabale isActive property of the userRuleVerification {id} is null", userRuleVerification.Iid); } else { @@ -107,7 +107,7 @@ public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jso { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the userRuleVerification {id} is null", userRuleVerification.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the userRuleVerification {id} is null", userRuleVerification.Iid); } else { @@ -119,7 +119,7 @@ public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jso { if(ruleProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale rule property of the userRuleVerification {id} is null", userRuleVerification.Iid); + Logger.Trace("The non-nullabale rule property of the userRuleVerification {id} is null", userRuleVerification.Iid); } else { @@ -131,7 +131,7 @@ public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jso { if(statusProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale status property of the userRuleVerification {id} is null", userRuleVerification.Iid); + Logger.Trace("The non-nullabale status property of the userRuleVerification {id} is null", userRuleVerification.Iid); } else { @@ -143,7 +143,7 @@ public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jso { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the userRuleVerification {id} is null", userRuleVerification.Iid); + Logger.Trace("The non-nullabale thingPreference property of the userRuleVerification {id} is null", userRuleVerification.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index 8fe97a0b4..b7cb379dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -115,7 +115,7 @@ public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { if(modifiedOnProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale modifiedOn property of the valueGroup {id} is null", valueGroup.Iid); + Logger.Trace("The non-nullabale modifiedOn property of the valueGroup {id} is null", valueGroup.Iid); } else { @@ -127,7 +127,7 @@ public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { if(nameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale name property of the valueGroup {id} is null", valueGroup.Iid); + Logger.Trace("The non-nullabale name property of the valueGroup {id} is null", valueGroup.Iid); } else { @@ -139,7 +139,7 @@ public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { if(shortNameProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale shortName property of the valueGroup {id} is null", valueGroup.Iid); + Logger.Trace("The non-nullabale shortName property of the valueGroup {id} is null", valueGroup.Iid); } else { @@ -151,7 +151,7 @@ public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) { - Logger.Debug("The non-nullabale thingPreference property of the valueGroup {id} is null", valueGroup.Iid); + Logger.Trace("The non-nullabale thingPreference property of the valueGroup {id} is null", valueGroup.Iid); } else { diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 50c743b8a..1084b3f83 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,459 +51,437 @@ namespace CDP4JsonSerializer public class ActionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ActionItem actionItem) + { + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actionee": - var allowedVersionsForActionee = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); + return; + } - if(!allowedVersionsForActionee.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.1.0"); writer.WritePropertyName("actionee"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(approvedByItem); } - break; - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.2.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "closeoutdate": - var allowedVersionsForCloseOutDate = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForCloseOutDate.Contains(requestedVersion)) + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("closeOutDate"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "closeoutstatement": - var allowedVersionsForCloseOutStatement = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForCloseOutStatement.Contains(requestedVersion)) + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("closeOutStatement"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.3.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("createdOn"u8); - - if(value != null) + if(actionItem.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(actionItem.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) - { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - } - writer.WriteEndArray(); - break; - case "duedate": - var allowedVersionsForDueDate = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - if(!allowedVersionsForDueDate.Contains(requestedVersion)) + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("dueDate"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WritePropertyName("languageCode"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actionee": + if(!AllowedVersionsPerProperty["actionee"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("actionee"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { @@ -510,20 +489,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -535,20 +507,31 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("author"u8); if(value != null) { @@ -560,49 +543,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListRelatedThing) + if(value is IEnumerable objectListCategory) { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(relatedThingItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -610,24 +579,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -635,49 +597,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + case "closeoutdate": + if(!AllowedVersionsPerProperty["closeOutDate"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + writer.WritePropertyName("closeOutDate"u8); + + if(value != null) { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - break; - case "status": - var allowedVersionsForStatus = new List + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForStatus.Contains(requestedVersion)) + break; + case "closeoutstatement": + if(!AllowedVersionsPerProperty["closeOutStatement"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("status"u8); + writer.WritePropertyName("closeOutStatement"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue((string)value); } else { @@ -685,19 +633,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("content"u8); if(value != null) { @@ -709,24 +651,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -734,396 +669,332 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ActionItem"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ActionItem actionItem) - { - throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.1.0"); - writer.WritePropertyName("actionee"u8); - writer.WriteStringValue(actionItem.Actionee); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { - writer.WriteStringValue(approvedByItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("discussion"u8); - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDiscussion) { - writer.WriteStringValue(categoryItem); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(actionItem.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actionItem.ClassKind.ToString()); - writer.WritePropertyName("closeOutDate"u8); + break; + case "duedate": + if(!AllowedVersionsPerProperty["dueDate"].Contains(requestedVersion)) + { + return; + } - if(actionItem.CloseOutDate.HasValue) + writer.WritePropertyName("dueDate"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("closeOutStatement"u8); - writer.WriteStringValue(actionItem.CloseOutStatement); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(actionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("dueDate"u8); - writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(actionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(actionItem.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(actionItem.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actionItem.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("languageCode"u8); + + if(value != null) { - writer.WriteStringValue(sourceAnnotationItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(actionItem.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(actionItem.Title); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.2.0"); - writer.WritePropertyName("actionee"u8); - writer.WriteStringValue(actionItem.Actionee); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(approvedByItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(actionItem.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actionItem.ClassKind.ToString()); - writer.WritePropertyName("closeOutDate"u8); - - if(actionItem.CloseOutDate.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("closeOutStatement"u8); - writer.WriteStringValue(actionItem.CloseOutStatement); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(actionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("dueDate"u8); - writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(actionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(actionItem.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(actionItem.PrimaryAnnotatedThing.HasValue) + + if(value != null) { - writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actionItem.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(actionItem.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(actionItem.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(actionItem.Title); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ActionItem for Version 1.3.0"); - writer.WritePropertyName("actionee"u8); - writer.WriteStringValue(actionItem.Actionee); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(actionItem.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(actionItem.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actionItem.ClassKind.ToString()); - writer.WritePropertyName("closeOutDate"u8); - - if(actionItem.CloseOutDate.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("closeOutStatement"u8); - writer.WriteStringValue(actionItem.CloseOutStatement); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(actionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("dueDate"u8); - writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("sourceAnnotation"u8); - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(excludedDomainItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(actionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(actionItem.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(actionItem.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actionItem.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(sourceAnnotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(actionItem.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(actionItem.ThingPreference); writer.WritePropertyName("title"u8); - writer.WriteStringValue(actionItem.Title); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActionItem"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actionee", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutStatement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "dueDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index c7484c138..b111405a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,328 +50,6 @@ namespace CDP4JsonSerializer /// public class ActualFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "actualstate": - var allowedVersionsForActualState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForActualState.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("actualState"u8); - - if(value is IEnumerable objectListActualState) - { - foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualStateItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeoption": - var allowedVersionsForExcludeOption = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludeOption.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludeOption"u8); - - if(value is IEnumerable objectListExcludeOption) - { - foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("owner"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "possiblefinitestatelist": - var allowedVersionsForPossibleFiniteStateList = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPossibleFiniteStateList.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("possibleFiniteStateList"u8); - - if(value is IEnumerable objectListPossibleFiniteStateList) - { - foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(possibleFiniteStateListItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteStateList"); - } - } - /// /// Serializes a into an /// @@ -397,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -406,6 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); writer.WriteStartArray("excludeOption"u8); @@ -416,6 +96,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("owner"u8); @@ -428,11 +109,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -441,6 +123,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -451,6 +134,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -459,6 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -467,6 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -481,11 +167,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -494,6 +181,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -504,6 +192,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -512,6 +201,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -520,6 +210,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -534,13 +225,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(actualFiniteStateList.ThingPreference); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteStateList for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(actualFiniteStateList.Actor.HasValue) @@ -560,6 +252,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -570,6 +263,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -578,6 +272,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -586,6 +281,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -600,6 +296,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); writer.WritePropertyName("thingPreference"u8); @@ -611,6 +308,260 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("actualState"u8); + + if(value is IEnumerable objectListActualState) + { + foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeoption": + if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludeOption"u8); + + if(value is IEnumerable objectListExcludeOption) + { + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblefinitestatelist": + if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteStateList"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 0f93c24da..f5addebc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,193 @@ namespace CDP4JsonSerializer /// public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(actualFiniteState.Actor.HasValue) + { + writer.WriteStringValue(actualFiniteState.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +244,7 @@ public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +252,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +270,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,15 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "kind": - var allowedVersionsForKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) { return; } @@ -214,14 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +378,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblestate": - var allowedVersionsForPossibleState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPossibleState.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) { return; } @@ -265,15 +396,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +414,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -320,181 +437,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ActualFiniteState actualFiniteState) - { - throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actualFiniteState.Iid); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(actualFiniteState.Kind.ToString()); - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actualFiniteState.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actualFiniteState.Iid); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(actualFiniteState.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actualFiniteState.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actualFiniteState.Iid); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(actualFiniteState.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actualFiniteState.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(actualFiniteState.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ActualFiniteState for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(actualFiniteState.Actor.HasValue) - { - writer.WriteStringValue(actualFiniteState.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(actualFiniteState.Iid); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(actualFiniteState.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(actualFiniteState.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(actualFiniteState.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 250910dbe..f9f993a00 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class AliasSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(alias.Actor.HasValue) + { + writer.WriteStringValue(alias.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class AliasSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -138,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "issynonym": - var allowedVersionsForIsSynonym = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsSynonym.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isSynonym"].Contains(requestedVersion)) { return; } @@ -240,15 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -266,14 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -291,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Alias alias) - { - throw new ArgumentException("The thing shall be a Alias", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(alias.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(alias.Content); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(alias.Iid); - writer.WritePropertyName("isSynonym"u8); - writer.WriteBooleanValue(alias.IsSynonym); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(alias.LanguageCode); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(alias.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(alias.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(alias.Iid); - writer.WritePropertyName("isSynonym"u8); - writer.WriteBooleanValue(alias.IsSynonym); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(alias.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(alias.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(alias.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(alias.Iid); - writer.WritePropertyName("isSynonym"u8); - writer.WriteBooleanValue(alias.IsSynonym); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(alias.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(alias.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(alias.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Alias for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(alias.Actor.HasValue) - { - writer.WriteStringValue(alias.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(alias.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(alias.Iid); - writer.WritePropertyName("isSynonym"u8); - writer.WriteBooleanValue(alias.IsSynonym); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(alias.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(alias.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(alias.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isSynonym", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 6b7bbe8aa..cba482db8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,185 @@ namespace CDP4JsonSerializer /// public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(andExpression.Actor.HasValue) + { + writer.WriteStringValue(andExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +236,7 @@ public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +298,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +316,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +334,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +352,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +370,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - var allowedVersionsForTerm = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTerm.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) { return; } @@ -265,13 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -294,173 +411,20 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not AndExpression andExpression) - { - throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(andExpression.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(andExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(andExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(andExpression.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing AndExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(andExpression.Actor.HasValue) - { - writer.WriteStringValue(andExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(andExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(andExpression.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 39477bf3f..c05f4dd9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,176 @@ namespace CDP4JsonSerializer /// public class ApprovalSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(approval.Actor.HasValue) + { + writer.WriteStringValue(approval.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +227,7 @@ public class ApprovalSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +235,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +253,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +271,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassification.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } @@ -136,14 +289,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -161,14 +307,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -186,14 +325,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -211,14 +343,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -236,14 +361,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -261,14 +379,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +397,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -311,14 +415,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -336,14 +433,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -361,14 +451,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -386,13 +469,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,168 +492,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Approval approval) - { - throw new ArgumentException("The thing shall be a Approval", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(approval.Author); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(approval.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(approval.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(approval.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(approval.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(approval.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(approval.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(approval.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(approval.Author); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(approval.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(approval.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(approval.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(approval.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(approval.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(approval.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(approval.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(approval.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Approval for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(approval.Actor.HasValue) - { - writer.WriteStringValue(approval.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(approval.Author); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(approval.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(approval.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(approval.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(approval.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(approval.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(approval.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(approval.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(approval.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index ee7e3e433..99a8b199c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,421 +51,437 @@ namespace CDP4JsonSerializer public class ArrayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ArrayParameterType arrayParameterType) + { + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(componentItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); - if(value is IEnumerable objectListAlias) + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteOrderedItem(dimensionItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(componentItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "component": - var allowedVersionsForComponent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); - if(!allowedVersionsForComponent.Contains(requestedVersion)) + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(dimensionItem); } - writer.WriteStartArray("component"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListComponent) + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(componentItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); break; - case "dimension": - var allowedVersionsForDimension = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDimension.Contains(requestedVersion)) + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("dimension"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDimension) + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(dimensionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(componentItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("dimension"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(dimensionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(arrayParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(arrayParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "isfinalized": - var allowedVersionsForIsFinalized = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - if(!allowedVersionsForIsFinalized.Contains(requestedVersion)) + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(componentItem); } - writer.WritePropertyName("isFinalized"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "istensor": - var allowedVersionsForIsTensor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); - if(!allowedVersionsForIsTensor.Contains(requestedVersion)) + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(dimensionItem); } - writer.WritePropertyName("isTensor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForName.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -472,77 +489,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) { - writer.WriteNullValue(); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } } - + + writer.WriteEndArray(); break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -550,411 +543,325 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "component": + if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("component"u8); + + if(value is IEnumerable objectListComponent) { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } } - + + writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ArrayParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ArrayParameterType arrayParameterType) - { - throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("definition"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(categoryItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "dimension": + if(!AllowedVersionsPerProperty["dimension"].Contains(requestedVersion)) { - writer.WriteOrderedItem(componentItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("dimension"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDimension) { - writer.WriteStringValue(definitionItem); + foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteOrderedItem(dimensionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(hyperLinkItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(arrayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(arrayParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(arrayParameterType.IsFinalized); - writer.WritePropertyName("isTensor"u8); - writer.WriteBooleanValue(arrayParameterType.IsTensor); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(arrayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(arrayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(arrayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(arrayParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteOrderedItem(componentItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteOrderedItem(dimensionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(arrayParameterType.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(arrayParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(arrayParameterType.IsFinalized); - writer.WritePropertyName("isTensor"u8); - writer.WriteBooleanValue(arrayParameterType.IsTensor); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(arrayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(arrayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(arrayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(arrayParameterType.Symbol); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "isfinalized": + if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) { - writer.WriteOrderedItem(componentItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isFinalized"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(dimensionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "istensor": + if(!AllowedVersionsPerProperty["isTensor"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isTensor"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(arrayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(arrayParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(arrayParameterType.IsFinalized); - writer.WritePropertyName("isTensor"u8); - writer.WriteBooleanValue(arrayParameterType.IsTensor); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(arrayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(arrayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(arrayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(arrayParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(arrayParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ArrayParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(arrayParameterType.Actor.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(arrayParameterType.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(componentItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteOrderedItem(dimensionItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(arrayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(arrayParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(arrayParameterType.IsFinalized); - writer.WritePropertyName("isTensor"u8); - writer.WriteBooleanValue(arrayParameterType.IsTensor); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(arrayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(arrayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(arrayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(arrayParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(arrayParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ArrayParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dimension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isTensor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index d908fa88d..4547107d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,203 @@ namespace CDP4JsonSerializer /// public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not BinaryNote binaryNote) + { + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.1.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.2.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryNote.Actor.HasValue) + { + writer.WriteStringValue(binaryNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +254,7 @@ public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "caption": - var allowedVersionsForCaption = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCaption.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["caption"].Contains(requestedVersion)) { return; } @@ -111,14 +298,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -136,14 +316,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -161,14 +334,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +352,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +370,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "filetype": - var allowedVersionsForFileType = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFileType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) { return; } @@ -261,14 +406,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +424,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +442,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -336,14 +460,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -361,14 +478,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -386,14 +496,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -411,13 +514,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -440,192 +537,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not BinaryNote binaryNote) - { - throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.1.0"); - writer.WritePropertyName("caption"u8); - writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryNote.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("fileType"u8); - writer.WriteStringValue(binaryNote.FileType); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryNote.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryNote.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.2.0"); - writer.WritePropertyName("caption"u8); - writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryNote.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("fileType"u8); - writer.WriteStringValue(binaryNote.FileType); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryNote.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryNote.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryNote.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(binaryNote.Actor.HasValue) - { - writer.WriteStringValue(binaryNote.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("caption"u8); - writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryNote.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("fileType"u8); - writer.WriteStringValue(binaryNote.FileType); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryNote.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryNote.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryNote.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "caption", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 68c5bc3ee..79fbf3310 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,266 +51,345 @@ namespace CDP4JsonSerializer public class BinaryRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not BinaryRelationshipRule binaryRelationshipRule) + { + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "forwardrelationshipname": - var allowedVersionsForForwardRelationshipName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForForwardRelationshipName.Contains(requestedVersion)) + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationshipRule.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(binaryRelationshipRule.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); break; - case "inverserelationshipname": - var allowedVersionsForInverseRelationshipName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForInverseRelationshipName.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("inverseRelationshipName"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -317,25 +397,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("isDeprecated"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -343,46 +433,67 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); break; - case "name": - var allowedVersionsForName = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForName.Contains(requestedVersion)) + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "forwardrelationshipname": + if(!AllowedVersionsPerProperty["forwardRelationshipName"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("forwardRelationshipName"u8); if(value != null) { @@ -394,21 +505,31 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relationshipcategory": - var allowedVersionsForRelationshipCategory = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForRelationshipCategory.Contains(requestedVersion)) + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("relationshipCategory"u8); + writer.WritePropertyName("iid"u8); if(value != null) { @@ -420,25 +541,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "inverserelationshipname": + if(!AllowedVersionsPerProperty["inverseRelationshipName"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("inverseRelationshipName"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((string)value); } else { @@ -446,25 +559,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -472,25 +577,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "sourcecategory": - var allowedVersionsForSourceCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSourceCategory.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("sourceCategory"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -498,25 +595,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "targetcategory": - var allowedVersionsForTargetCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTargetCategory.Contains(requestedVersion)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("targetCategory"u8); + writer.WritePropertyName("name"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -524,23 +613,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "relationshipcategory": + if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("relationshipCategory"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -548,307 +631,126 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationshipRule"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not BinaryRelationshipRule binaryRelationshipRule) - { - throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("forwardRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationshipRule.Iid); - writer.WritePropertyName("inverseRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationshipRule.Name); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryRelationshipRule.ShortName); - writer.WritePropertyName("sourceCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.SourceCategory); - writer.WritePropertyName("targetCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.TargetCategory); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("forwardRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationshipRule.Iid); - writer.WritePropertyName("inverseRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationshipRule.Name); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryRelationshipRule.ShortName); - writer.WritePropertyName("sourceCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.SourceCategory); - writer.WritePropertyName("targetCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.TargetCategory); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + case "sourcecategory": + if(!AllowedVersionsPerProperty["sourceCategory"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("sourceCategory"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("forwardRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "targetcategory": + if(!AllowedVersionsPerProperty["targetCategory"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationshipRule.Iid); - writer.WritePropertyName("inverseRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationshipRule.Name); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryRelationshipRule.ShortName); - writer.WritePropertyName("sourceCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.SourceCategory); writer.WritePropertyName("targetCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.TargetCategory); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryRelationshipRule.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationshipRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(binaryRelationshipRule.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(binaryRelationshipRule.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("forwardRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationshipRule.Iid); - writer.WritePropertyName("inverseRelationshipName"u8); - writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationshipRule.Name); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(binaryRelationshipRule.ShortName); - writer.WritePropertyName("sourceCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.SourceCategory); - writer.WritePropertyName("targetCategory"u8); - writer.WriteStringValue(binaryRelationshipRule.TargetCategory); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryRelationshipRule.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationshipRule"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "forwardRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "inverseRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "targetCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index f7c686f76..a719d0883 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,240 @@ namespace CDP4JsonSerializer /// public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not BinaryRelationship binaryRelationship) + { + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationship.Actor.HasValue) + { + writer.WriteStringValue(binaryRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +291,7 @@ public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerialize /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +299,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +317,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -112,15 +335,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -138,14 +353,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +371,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +389,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +407,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,13 +425,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -263,15 +443,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -289,14 +461,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - var allowedVersionsForParameterValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) { return; } @@ -314,15 +479,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -340,15 +497,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "source": - var allowedVersionsForSource = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSource.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) { return; } @@ -366,15 +515,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "target": - var allowedVersionsForTarget = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTarget.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) { return; } @@ -392,13 +533,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -421,225 +556,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not BinaryRelationship binaryRelationship) - { - throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.0.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationship.Iid); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryRelationship.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationship.RevisionNumber); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(binaryRelationship.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(binaryRelationship.Target); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationship.RevisionNumber); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(binaryRelationship.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(binaryRelationship.Target); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationship.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationship.RevisionNumber); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(binaryRelationship.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(binaryRelationship.Target); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryRelationship.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing BinaryRelationship for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(binaryRelationship.Actor.HasValue) - { - writer.WriteStringValue(binaryRelationship.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(binaryRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(binaryRelationship.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(binaryRelationship.RevisionNumber); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(binaryRelationship.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(binaryRelationship.Target); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(binaryRelationship.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index 55e95e544..abc6c6d35 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,218 @@ namespace CDP4JsonSerializer /// public class BookSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Book book) + { + throw new ArgumentException("The thing shall be a Book", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(book.Actor.HasValue) + { + writer.WriteStringValue(book.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +269,7 @@ public class BookSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +277,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +295,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -111,14 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +331,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -161,14 +349,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -186,14 +367,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -211,14 +385,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -236,14 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -261,14 +421,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -286,14 +439,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -311,14 +457,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -336,14 +475,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "section": - var allowedVersionsForSection = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSection.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["section"].Contains(requestedVersion)) { return; } @@ -361,14 +493,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +511,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,204 +534,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Book book) - { - throw new ArgumentException("The thing shall be a Book", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(book.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(book.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(book.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(book.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(sectionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(book.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(book.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(book.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(book.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(book.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(sectionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(book.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(book.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Book for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(book.Actor.HasValue) - { - writer.WriteStringValue(book.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(book.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(book.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(book.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(book.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(sectionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(book.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(book.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "section", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index 8bd6e5c00..60566d570 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,349 @@ namespace CDP4JsonSerializer public class BooleanParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not BooleanParameterType booleanParameterType) + { + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(booleanParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(booleanParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the BooleanParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not BooleanParameterType booleanParameterType) - { - throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(booleanParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(booleanParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(booleanParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(booleanParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(booleanParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(booleanParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(booleanParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(booleanParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(booleanParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(booleanParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(booleanParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(booleanParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(booleanParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(booleanParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(booleanParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(booleanParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(booleanParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(booleanParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(booleanParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing BooleanParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(booleanParameterType.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(booleanParameterType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(booleanParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(booleanParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(booleanParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(booleanParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(booleanParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(booleanParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(booleanParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the BooleanParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index f7d66e3c9..a20241ef0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,170 @@ namespace CDP4JsonSerializer /// public class BoundsSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Bounds bounds) + { + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(bounds.Actor.HasValue) + { + writer.WriteStringValue(bounds.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +221,7 @@ public class BoundsSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +229,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +247,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +265,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "height": - var allowedVersionsForHeight = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHeight.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["height"].Contains(requestedVersion)) { return; } @@ -186,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -211,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -236,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -261,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -286,13 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -310,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "width": - var allowedVersionsForWidth = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForWidth.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["width"].Contains(requestedVersion)) { return; } @@ -335,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "x": - var allowedVersionsForX = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForX.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) { return; } @@ -360,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "y": - var allowedVersionsForY = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForY.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) { return; } @@ -390,162 +468,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Bounds bounds) - { - throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("height"u8); - writer.WriteNumberValue(bounds.Height); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(bounds.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(bounds.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(bounds.RevisionNumber); - writer.WritePropertyName("width"u8); - writer.WriteNumberValue(bounds.Width); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(bounds.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(bounds.Y); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("height"u8); - writer.WriteNumberValue(bounds.Height); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(bounds.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(bounds.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(bounds.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(bounds.ThingPreference); - writer.WritePropertyName("width"u8); - writer.WriteNumberValue(bounds.Width); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(bounds.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(bounds.Y); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Bounds for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(bounds.Actor.HasValue) - { - writer.WriteStringValue(bounds.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("height"u8); - writer.WriteNumberValue(bounds.Height); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(bounds.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(bounds.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(bounds.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(bounds.ThingPreference); - writer.WritePropertyName("width"u8); - writer.WriteNumberValue(bounds.Width); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(bounds.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(bounds.Y); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "height", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "width", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index bbcf92878..9ae30150d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,253 @@ namespace CDP4JsonSerializer /// public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not BuiltInRuleVerification builtInRuleVerification) + { + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(builtInRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +304,7 @@ public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSeri /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +312,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +330,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +366,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "executedon": - var allowedVersionsForExecutedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExecutedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) { return; } @@ -188,15 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - var allowedVersionsForIsActive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsActive.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) { return; } @@ -240,14 +438,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -291,15 +474,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,15 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "status": - var allowedVersionsForStatus = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { return; } @@ -343,13 +510,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -367,15 +528,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "violation": - var allowedVersionsForViolation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForViolation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) { return; } @@ -398,241 +551,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not BuiltInRuleVerification builtInRuleVerification) - { - throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WritePropertyName("executedOn"u8); - - if(builtInRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(builtInRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(builtInRuleVerification.IsActive); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(builtInRuleVerification.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(builtInRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(builtInRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(builtInRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(builtInRuleVerification.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(builtInRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(builtInRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(builtInRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(builtInRuleVerification.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(builtInRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing BuiltInRuleVerification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(builtInRuleVerification.Actor.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(builtInRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(builtInRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(builtInRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(builtInRuleVerification.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(builtInRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index 65054c330..92545d84e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,516 +51,231 @@ namespace CDP4JsonSerializer public class CategorySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var permissibleClassItem in category.PermissibleClass) { - return; + writer.WriteStringValue(permissibleClassItem.ToString()); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(superCategoryItem); } + writer.WriteEndArray(); + break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var permissibleClassItem in category.PermissibleClass) { - return; + writer.WriteStringValue(permissibleClassItem.ToString()); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(superCategoryItem); } - + writer.WriteEndArray(); + break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isabstract": - var allowedVersionsForIsAbstract = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForIsAbstract.Contains(requestedVersion)) + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("isAbstract"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "permissibleclass": - var allowedVersionsForPermissibleClass = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPermissibleClass.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("permissibleClass"u8); - - if(value is IEnumerable objectListPermissibleClass) - { - foreach(var permissibleClassItem in objectListPermissibleClass) - { - writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "supercategory": - var allowedVersionsForSuperCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSuperCategory.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("superCategory"u8); - - if(value is IEnumerable objectListSuperCategory) - { - foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(superCategoryItem); - } - } - writer.WriteEndArray(); - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Category"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Category category) - { - throw new ArgumentException("The thing shall be a Category", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); writer.WritePropertyName("isAbstract"u8); writer.WriteBooleanValue(category.IsAbstract); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); writer.WriteStartArray("permissibleClass"u8); @@ -570,6 +286,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); @@ -582,9 +299,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(category.Actor.HasValue) + { + writer.WriteStringValue(category.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) @@ -593,6 +324,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -603,6 +335,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -611,6 +344,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -619,6 +353,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -627,6 +362,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); writer.WritePropertyName("isAbstract"u8); @@ -645,6 +381,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); @@ -657,178 +394,365 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.2.0"); - writer.WriteStartArray("alias"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("actor"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(category.Iid); - writer.WritePropertyName("isAbstract"u8); - writer.WriteBooleanValue(category.IsAbstract); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(category.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); + writer.WriteStartArray("alias"u8); - foreach(var permissibleClassItem in category.PermissibleClass) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(permissibleClassItem.ToString()); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(category.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); - - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { - writer.WriteStringValue(superCategoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(category.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Category for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(category.Actor.HasValue) + writer.WritePropertyName("classKind"u8); + + if(value != null) { - writer.WriteStringValue(category.Actor.Value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(category.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(category.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isabstract": + if(!AllowedVersionsPerProperty["isAbstract"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("isAbstract"u8); - writer.WriteBooleanValue(category.IsAbstract); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(category.IsDeprecated); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("name"u8); - writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var permissibleClassItem in category.PermissibleClass) + break; + case "permissibleclass": + if(!AllowedVersionsPerProperty["permissibleClass"].Contains(requestedVersion)) { - writer.WriteStringValue(permissibleClassItem.ToString()); + return; } + writer.WriteStartArray("permissibleClass"u8); + + if(value is IEnumerable objectListPermissibleClass) + { + foreach(var permissibleClassItem in objectListPermissibleClass) + { + writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); + } + } + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(category.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + break; + case "supercategory": + if(!AllowedVersionsPerProperty["superCategory"].Contains(requestedVersion)) { - writer.WriteStringValue(superCategoryItem); + return; } + writer.WriteStartArray("superCategory"u8); + + if(value is IEnumerable objectListSuperCategory) + { + foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + } + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(category.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Category"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAbstract", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "permissibleClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "superCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index eaa2878c0..f51c63661 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,330 +51,460 @@ namespace CDP4JsonSerializer public class ChangeProposalSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ChangeProposal changeProposal) + { + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); break; - case "changerequest": - var allowedVersionsForChangeRequest = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForChangeRequest.Contains(requestedVersion)) + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("changeRequest"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeProposal.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(changeProposal.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(discussionItem); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("discussion"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(value is IEnumerable objectListDiscussion) + if(changeProposal.PrimaryAnnotatedThing.HasValue) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("approvedBy"u8); - if(value is IEnumerable objectListExcludedDomain) + if(value is IEnumerable objectListApprovedBy) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(approvedByItem); } } writer.WriteEndArray(); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedPerson) + if(value is IEnumerable objectListCategory) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + case "changerequest": + if(!AllowedVersionsPerProperty["changeRequest"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("changeRequest"u8); if(value != null) { @@ -385,24 +516,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -410,24 +534,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,24 +552,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -460,24 +570,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -485,49 +588,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListRelatedThing) + if(value is IEnumerable objectListExcludedDomain) { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(relatedThingItem); + writer.WriteStringValue(excludedDomainItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -535,20 +660,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -560,49 +678,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) - { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - } - - writer.WriteEndArray(); - break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("status"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -610,23 +696,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("owner"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -634,24 +714,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -659,351 +732,167 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeProposal"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ChangeProposal changeProposal) - { - throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeRequest"u8); - writer.WriteStringValue(changeProposal.ChangeRequest); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeProposal.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeProposal.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeProposal.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(excludedDomainItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeProposal.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeProposal.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeProposal.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeProposal.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeProposal.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeProposal.Title); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(approvedByItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("changeRequest"u8); - writer.WriteStringValue(changeProposal.ChangeRequest); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeProposal.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeProposal.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeProposal.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("sourceAnnotation"u8); - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(excludedDomainItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeProposal.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeProposal.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeProposal.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeProposal.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeProposal.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(sourceAnnotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeProposal.Status.ToString()); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(changeProposal.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeProposal.Title); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeProposal for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(changeProposal.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(changeProposal.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeRequest"u8); - writer.WriteStringValue(changeProposal.ChangeRequest); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeProposal.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeProposal.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeProposal.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeProposal.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeProposal.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeProposal.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeProposal.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeProposal.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeProposal.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(changeProposal.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeProposal.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeProposal"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeRequest", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index 2a227e46e..a7b2b58e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,305 +51,382 @@ namespace CDP4JsonSerializer public class ChangeRequestSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeRequest.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(changeRequest.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WriteStartArray("discussion"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDiscussion) + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(changeRequest.PrimaryAnnotatedThing.HasValue) { - return; + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("relatedThing"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(relatedThingItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -360,24 +438,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("author"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -385,24 +474,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -410,24 +510,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,24 +528,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -460,49 +546,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) - { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -510,74 +564,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) { - writer.WriteStringValue((string)value); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListSourceAnnotation) + if(value is IEnumerable objectListExcludedPerson) { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(sourceAnnotationItem); + writer.WriteStringValue(excludedPersonItem); } } writer.WriteEndArray(); break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("status"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -585,19 +636,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -609,24 +654,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -634,345 +672,202 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeRequest"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ChangeRequest changeRequest) - { - throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeRequest.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeRequest.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeRequest.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeRequest.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeRequest.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeRequest.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeRequest.PrimaryAnnotatedThing.HasValue) + + if(value != null) { - writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeRequest.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeRequest.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeRequest.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeRequest.Title); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeRequest.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeRequest.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeRequest.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeRequest.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeRequest.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeRequest.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeRequest.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeRequest.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeRequest.ShortName); writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeRequest.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(changeRequest.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeRequest.Title); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ChangeRequest for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } - if(changeRequest.Actor.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(changeRequest.Actor.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(changeRequest.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(changeRequest.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(changeRequest.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(changeRequest.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(changeRequest.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(changeRequest.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(changeRequest.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(changeRequest.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(changeRequest.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(changeRequest.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(changeRequest.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(changeRequest.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeRequest"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index 51f47dc83..423ff51c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,189 @@ namespace CDP4JsonSerializer /// public class CitationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Citation citation) + { + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(citation.Actor.HasValue) + { + writer.WriteStringValue(citation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +240,7 @@ public class CitationSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +248,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +266,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +284,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +302,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +320,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,15 +338,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isadaptation": - var allowedVersionsForIsAdaptation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsAdaptation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isAdaptation"].Contains(requestedVersion)) { return; } @@ -214,15 +356,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "location": - var allowedVersionsForLocation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLocation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["location"].Contains(requestedVersion)) { return; } @@ -240,14 +374,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +392,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "remark": - var allowedVersionsForRemark = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRemark.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["remark"].Contains(requestedVersion)) { return; } @@ -291,15 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,15 +428,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -343,15 +446,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "source": - var allowedVersionsForSource = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSource.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) { return; } @@ -369,13 +464,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -398,181 +487,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Citation citation) - { - throw new ArgumentException("The thing shall be a Citation", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(citation.Iid); - writer.WritePropertyName("isAdaptation"u8); - writer.WriteBooleanValue(citation.IsAdaptation); - writer.WritePropertyName("location"u8); - writer.WriteStringValue(citation.Location); - writer.WritePropertyName("remark"u8); - writer.WriteStringValue(citation.Remark); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(citation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(citation.ShortName); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(citation.Source); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(citation.Iid); - writer.WritePropertyName("isAdaptation"u8); - writer.WriteBooleanValue(citation.IsAdaptation); - writer.WritePropertyName("location"u8); - writer.WriteStringValue(citation.Location); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("remark"u8); - writer.WriteStringValue(citation.Remark); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(citation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(citation.ShortName); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(citation.Source); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(citation.Iid); - writer.WritePropertyName("isAdaptation"u8); - writer.WriteBooleanValue(citation.IsAdaptation); - writer.WritePropertyName("location"u8); - writer.WriteStringValue(citation.Location); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("remark"u8); - writer.WriteStringValue(citation.Remark); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(citation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(citation.ShortName); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(citation.Source); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(citation.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Citation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(citation.Actor.HasValue) - { - writer.WriteStringValue(citation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(citation.Iid); - writer.WritePropertyName("isAdaptation"u8); - writer.WriteBooleanValue(citation.IsAdaptation); - writer.WritePropertyName("location"u8); - writer.WriteStringValue(citation.Location); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("remark"u8); - writer.WriteStringValue(citation.Remark); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(citation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(citation.ShortName); - writer.WritePropertyName("source"u8); - writer.WriteStringValue(citation.Source); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(citation.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAdaptation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "location", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "remark", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 6d9c521f6..24f898ef3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,181 @@ namespace CDP4JsonSerializer /// public class ColorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Color color) + { + throw new ArgumentException("The thing shall be a Color", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.0.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.1.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.2.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(color.Actor.HasValue) + { + writer.WriteStringValue(color.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +232,7 @@ public class ColorSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +240,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +258,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "blue": - var allowedVersionsForBlue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForBlue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["blue"].Contains(requestedVersion)) { return; } @@ -112,15 +276,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -138,14 +294,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +312,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +330,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "green": - var allowedVersionsForGreen = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForGreen.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["green"].Contains(requestedVersion)) { return; } @@ -214,15 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -240,14 +366,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -291,15 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "red": - var allowedVersionsForRed = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRed.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["red"].Contains(requestedVersion)) { return; } @@ -317,15 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -343,13 +438,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -372,173 +461,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Color color) - { - throw new ArgumentException("The thing shall be a Color", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.0.0"); - writer.WritePropertyName("blue"u8); - writer.WriteNumberValue(color.Blue); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(color.ClassKind.ToString()); - writer.WritePropertyName("green"u8); - writer.WriteNumberValue(color.Green); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(color.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(color.Name); - writer.WritePropertyName("red"u8); - writer.WriteNumberValue(color.Red); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(color.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.1.0"); - writer.WritePropertyName("blue"u8); - writer.WriteNumberValue(color.Blue); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("green"u8); - writer.WriteNumberValue(color.Green); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(color.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(color.Name); - writer.WritePropertyName("red"u8); - writer.WriteNumberValue(color.Red); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(color.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.2.0"); - writer.WritePropertyName("blue"u8); - writer.WriteNumberValue(color.Blue); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("green"u8); - writer.WriteNumberValue(color.Green); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(color.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(color.Name); - writer.WritePropertyName("red"u8); - writer.WriteNumberValue(color.Red); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(color.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(color.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Color for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(color.Actor.HasValue) - { - writer.WriteStringValue(color.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("blue"u8); - writer.WriteNumberValue(color.Blue); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("green"u8); - writer.WriteNumberValue(color.Green); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(color.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(color.Name); - writer.WritePropertyName("red"u8); - writer.WriteNumberValue(color.Red); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(color.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(color.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "blue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "green", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "red", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index a5f4403a5..f246db2b5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,245 @@ namespace CDP4JsonSerializer /// public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not CommonFileStore commonFileStore) + { + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(commonFileStore.Actor.HasValue) + { + writer.WriteStringValue(commonFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +296,7 @@ public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -138,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "file": - var allowedVersionsForFile = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFile.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) { return; } @@ -214,15 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "folder": - var allowedVersionsForFolder = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFolder.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) { return; } @@ -240,15 +430,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -266,14 +448,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -291,15 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -317,15 +484,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -343,15 +502,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -369,13 +520,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -398,229 +543,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not CommonFileStore commonFileStore) - { - throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(commonFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(commonFileStore.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(commonFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(commonFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(commonFileStore.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(commonFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(commonFileStore.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(commonFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(commonFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(commonFileStore.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(commonFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(commonFileStore.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(commonFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(commonFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(commonFileStore.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(commonFileStore.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing CommonFileStore for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(commonFileStore.Actor.HasValue) - { - writer.WriteStringValue(commonFileStore.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(commonFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(commonFileStore.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(commonFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(commonFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(commonFileStore.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(commonFileStore.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index 7ab792415..09cc7998b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,393 @@ namespace CDP4JsonSerializer public class CompoundParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(componentItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(componentItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "component": - var allowedVersionsForComponent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForComponent.Contains(requestedVersion)) + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("component"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListComponent) + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(componentItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(componentItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(compoundParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(compoundParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(componentItem); } - break; - case "isfinalized": - var allowedVersionsForIsFinalized = new List + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIsFinalized.Contains(requestedVersion)) + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("isFinalized"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +445,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,51 +499,107 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List + case "component": + if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("component"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(value is IEnumerable objectListComponent) + { + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } - if(value != null) + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue((string)value); + return; } - else + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteNullValue(); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; } + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); break; - case "symbol": - var allowedVersionsForSymbol = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -498,23 +607,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -522,347 +625,161 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the CompoundParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not CompoundParameterType compoundParameterType) - { - throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(componentItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + case "isfinalized": + if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(compoundParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(compoundParameterType.IsDeprecated); writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(compoundParameterType.IsFinalized); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(compoundParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(compoundParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(compoundParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(compoundParameterType.Symbol); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(componentItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(compoundParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(compoundParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(compoundParameterType.IsFinalized); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(compoundParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(compoundParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(compoundParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(compoundParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(componentItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(compoundParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(compoundParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(compoundParameterType.IsFinalized); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(compoundParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(compoundParameterType.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(compoundParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(compoundParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(compoundParameterType.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing CompoundParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(compoundParameterType.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(compoundParameterType.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteOrderedItem(componentItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(compoundParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(compoundParameterType.IsDeprecated); - writer.WritePropertyName("isFinalized"u8); - writer.WriteBooleanValue(compoundParameterType.IsFinalized); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(compoundParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(compoundParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(compoundParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(compoundParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(compoundParameterType.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the CompoundParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index 6e2f969cc..412e656be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,391 +51,393 @@ namespace CDP4JsonSerializer public class ConstantSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not Constant constant) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListCategory) + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(constant.Scale.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDefinition) + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(constant.Scale.HasValue) { - return; + writer.WriteStringValue(constant.Scale.Value); } - - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + else { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteNullValue(); } - - writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(constant.Scale.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("name"u8); - - if(value != null) + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(constant.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(constant.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "parametertype": - var allowedVersionsForParameterType = new List + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("parameterType"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(constant.Scale.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForScale.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("scale"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -446,49 +449,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -496,371 +503,277 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Constant"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Constant constant) - { - throw new ArgumentException("The thing shall be a Constant", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("definition"u8); - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(aliasItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(definitionItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(constant.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(constant.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(constant.Name); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(constant.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(constant.RevisionNumber); - writer.WritePropertyName("scale"u8); + writer.WriteStartArray("excludedPerson"u8); - if(constant.Scale.HasValue) - { - writer.WriteStringValue(constant.Scale.Value); - } - else + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteNullValue(); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(constant.ShortName); - writer.WriteString("value"u8, constant.Value.ToJsonString()); + + writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(categoryItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(constant.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(constant.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(constant.Name); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(constant.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(constant.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(constant.Scale.HasValue) + + if(value != null) { - writer.WriteStringValue(constant.Scale.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(constant.ShortName); - writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(constant.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(constant.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(constant.Name); writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(constant.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(constant.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(constant.Scale.HasValue) + + if(value != null) { - writer.WriteStringValue(constant.Scale.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(constant.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(constant.ThingPreference); - writer.WriteString("value"u8, constant.Value.ToJsonString()); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Constant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(constant.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(constant.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("scale"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(constant.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(constant.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(constant.Name); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(constant.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(constant.RevisionNumber); - writer.WritePropertyName("scale"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(constant.Scale.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(constant.Scale.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(constant.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(constant.ThingPreference); - writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Constant"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 494f45e35..8d6aaf3db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,330 +51,460 @@ namespace CDP4JsonSerializer public class ContractChangeNoticeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ContractChangeNotice contractChangeNotice) + { + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); break; - case "changeproposal": - var allowedVersionsForChangeProposal = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForChangeProposal.Contains(requestedVersion)) + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("changeProposal"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(contractChangeNotice.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(contractChangeNotice.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(discussionItem); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("discussion"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(value is IEnumerable objectListDiscussion) + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("approvedBy"u8); - if(value is IEnumerable objectListExcludedDomain) + if(value is IEnumerable objectListApprovedBy) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(approvedByItem); } } writer.WriteEndArray(); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedPerson) + if(value is IEnumerable objectListCategory) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + case "changeproposal": + if(!AllowedVersionsPerProperty["changeProposal"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("changeProposal"u8); if(value != null) { @@ -385,24 +516,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -410,24 +534,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,24 +552,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -460,24 +570,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -485,49 +588,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListRelatedThing) + if(value is IEnumerable objectListExcludedDomain) { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(relatedThingItem); + writer.WriteStringValue(excludedDomainItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -535,20 +660,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -560,49 +678,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) - { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - } - - writer.WriteEndArray(); - break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("status"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -610,23 +696,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("owner"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -634,24 +714,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -659,351 +732,167 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ContractChangeNotice"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ContractChangeNotice contractChangeNotice) - { - throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeProposal"u8); - writer.WriteStringValue(contractChangeNotice.ChangeProposal); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(contractChangeNotice.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(contractChangeNotice.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(excludedDomainItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(contractChangeNotice.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(contractChangeNotice.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(contractChangeNotice.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(contractChangeNotice.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(contractChangeNotice.Title); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(approvedByItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("changeProposal"u8); - writer.WriteStringValue(contractChangeNotice.ChangeProposal); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(contractChangeNotice.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(contractChangeNotice.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("sourceAnnotation"u8); - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(excludedDomainItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(contractChangeNotice.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(contractChangeNotice.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(contractChangeNotice.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(contractChangeNotice.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(sourceAnnotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(contractChangeNotice.Status.ToString()); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(contractChangeNotice.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(contractChangeNotice.Title); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ContractChangeNotice for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(contractChangeNotice.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(contractChangeNotice.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeProposal"u8); - writer.WriteStringValue(contractChangeNotice.ChangeProposal); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(contractChangeNotice.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(contractChangeNotice.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(contractChangeNotice.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(contractChangeNotice.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(contractChangeNotice.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(contractChangeNotice.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(contractChangeNotice.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(contractChangeNotice.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(contractChangeNotice.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ContractChangeNotice"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeProposal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index 74aba1f5b..e8a0f05f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,370 +51,449 @@ namespace CDP4JsonSerializer public class CyclicRatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not CyclicRatioScale cyclicRatioScale) + { + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListAlias) + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(mappingToReferenceScaleItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(cyclicRatioScale.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(cyclicRatioScale.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "ismaximuminclusive": - var allowedVersionsForIsMaximumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "isminimuminclusive": - var allowedVersionsForIsMinimumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "mappingtoreferencescale": - var allowedVersionsForMappingToReferenceScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListMappingToReferenceScale) + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStringValue(mappingToReferenceScaleItem); } - + writer.WriteEndArray(); - break; - case "maximumpermissiblevalue": - var allowedVersionsForMaximumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - break; - case "minimumpermissiblevalue": - var allowedVersionsForMinimumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -421,50 +501,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "modulus": - var allowedVersionsForModulus = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModulus.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modulus"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,48 +537,176 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - case "negativevalueconnotation": - var allowedVersionsForNegativeValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("negativeValueConnotation"u8); - + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + if(value != null) { writer.WriteStringValue((string)value); @@ -524,16 +717,98 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "numberset": - var allowedVersionsForNumberSet = new List + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modulus": + if(!AllowedVersionsPerProperty["modulus"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modulus"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) { return; } @@ -551,15 +826,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - var allowedVersionsForPositiveValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) { return; } @@ -577,15 +844,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -603,15 +862,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -629,13 +880,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -653,15 +898,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { return; } @@ -679,15 +916,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - var allowedVersionsForValueDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { return; } @@ -710,397 +939,36 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not CyclicRatioScale cyclicRatioScale) - { - throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(cyclicRatioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); - writer.WritePropertyName("modulus"u8); - writer.WriteStringValue(cyclicRatioScale.Modulus); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(cyclicRatioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(cyclicRatioScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(cyclicRatioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("modulus"u8); - writer.WriteStringValue(cyclicRatioScale.Modulus); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(cyclicRatioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(cyclicRatioScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(cyclicRatioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("modulus"u8); - writer.WriteStringValue(cyclicRatioScale.Modulus); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(cyclicRatioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(cyclicRatioScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(cyclicRatioScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing CyclicRatioScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(cyclicRatioScale.Actor.HasValue) - { - writer.WriteStringValue(cyclicRatioScale.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(cyclicRatioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("modulus"u8); - writer.WriteStringValue(cyclicRatioScale.Modulus); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(cyclicRatioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(cyclicRatioScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(cyclicRatioScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modulus", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 9835c3d53..9e479ed0c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,349 @@ namespace CDP4JsonSerializer public class DateParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DateParameterType dateParameterType) + { + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(dateParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(dateParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DateParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DateParameterType dateParameterType) - { - throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dateParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DateParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(dateParameterType.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(dateParameterType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dateParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index 403c97965..c75c8db26 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,349 @@ namespace CDP4JsonSerializer public class DateTimeParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DateTimeParameterType dateTimeParameterType) + { + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(dateTimeParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(dateTimeParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DateTimeParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DateTimeParameterType dateTimeParameterType) - { - throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateTimeParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateTimeParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateTimeParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateTimeParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateTimeParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateTimeParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateTimeParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateTimeParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateTimeParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateTimeParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateTimeParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateTimeParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dateTimeParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DateTimeParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(dateTimeParameterType.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(dateTimeParameterType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dateTimeParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(dateTimeParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(dateTimeParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(dateTimeParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dateTimeParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateTimeParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index 9f49314eb..1bcb6fc13 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,369 +51,401 @@ namespace CDP4JsonSerializer public class DecompositionRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(containedCategoryItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListAlias) + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteNumberValue(decompositionRule.MaxContained.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); break; - case "containedcategory": - var allowedVersionsForContainedCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForContainedCategory.Contains(requestedVersion)) + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); writer.WriteStartArray("containedCategory"u8); - if(value is IEnumerable objectListContainedCategory) + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedCategoryItem); - } + writer.WriteStringValue(containedCategoryItem); } - + writer.WriteEndArray(); - break; - case "containingcategory": - var allowedVersionsForContainingCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForContainingCategory.Contains(requestedVersion)) + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("containingCategory"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(decompositionRule.MaxContained.HasValue) { - return; + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(containedCategoryItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteNumberValue(decompositionRule.MaxContained.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(decompositionRule.Actor.HasValue) { - return; + writer.WriteStringValue(decompositionRule.Actor.Value); + } + else + { + writer.WriteNullValue(); } - writer.WritePropertyName("isDeprecated"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(aliasItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(containedCategoryItem); } - break; - case "maxcontained": - var allowedVersionsForMaxContained = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForMaxContained.Contains(requestedVersion)) + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("maxContained"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "mincontained": - var allowedVersionsForMinContained = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForMinContained.Contains(requestedVersion)) + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("minContained"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteNumberValue(decompositionRule.MaxContained.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { @@ -420,51 +453,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,49 +489,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "containedcategory": + if(!AllowedVersionsPerProperty["containedCategory"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("containedCategory"u8); + + if(value is IEnumerable objectListContainedCategory) { - writer.WriteNullValue(); + foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "containingcategory": + if(!AllowedVersionsPerProperty["containingCategory"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("containingCategory"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -522,359 +525,269 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DecompositionRule"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DecompositionRule decompositionRule) - { - throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); + writer.WriteStartArray("definition"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(containedCategoryItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("containingCategory"u8); - writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(hyperLinkItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(decompositionRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(decompositionRule.IsDeprecated); - writer.WritePropertyName("maxContained"u8); - - if(decompositionRule.MaxContained.HasValue) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNumberValue(decompositionRule.MaxContained.Value); + return; } - else + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteNullValue(); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - - writer.WritePropertyName("minContained"u8); - writer.WriteNumberValue(decompositionRule.MinContained); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(decompositionRule.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(decompositionRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(decompositionRule.ShortName); + + writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(containedCategoryItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("containingCategory"u8); - writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(decompositionRule.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(decompositionRule.IsDeprecated); - writer.WritePropertyName("maxContained"u8); - - if(decompositionRule.MaxContained.HasValue) + + if(value != null) { - writer.WriteNumberValue(decompositionRule.MaxContained.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("minContained"u8); - writer.WriteNumberValue(decompositionRule.MinContained); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(decompositionRule.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(decompositionRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(decompositionRule.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "maxcontained": + if(!AllowedVersionsPerProperty["maxContained"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("maxContained"u8); + + if(value != null) { - writer.WriteStringValue(containedCategoryItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("containingCategory"u8); - writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "mincontained": + if(!AllowedVersionsPerProperty["minContained"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("minContained"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(decompositionRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(decompositionRule.IsDeprecated); - writer.WritePropertyName("maxContained"u8); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(decompositionRule.MaxContained.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteNumberValue(decompositionRule.MaxContained.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("minContained"u8); - writer.WriteNumberValue(decompositionRule.MinContained); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(decompositionRule.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(decompositionRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(decompositionRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(decompositionRule.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DecompositionRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - if(decompositionRule.Actor.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(decompositionRule.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(containedCategoryItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("containingCategory"u8); - writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(decompositionRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(decompositionRule.IsDeprecated); - writer.WritePropertyName("maxContained"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(decompositionRule.MaxContained.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteNumberValue(decompositionRule.MaxContained.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("minContained"u8); - writer.WriteNumberValue(decompositionRule.MinContained); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(decompositionRule.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(decompositionRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(decompositionRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(decompositionRule.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DecompositionRule"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index dd3899aae..8554d8d6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,354 +50,6 @@ namespace CDP4JsonSerializer /// public class DefinitionSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "citation": - var allowedVersionsForCitation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCitation.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("citation"u8); - - if(value is IEnumerable objectListCitation) - { - foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(citationItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "content": - var allowedVersionsForContent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("content"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "example": - var allowedVersionsForExample = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExample.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("example"u8); - - if(value is IEnumerable objectListExample) - { - foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(exampleItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("languageCode"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "note": - var allowedVersionsForNote = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNote.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("note"u8); - - if(value is IEnumerable objectListNote) - { - foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(noteItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Definition"); - } - } - /// /// Serializes a into an /// @@ -423,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -432,6 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); @@ -444,6 +98,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); @@ -456,11 +111,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -469,6 +125,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); @@ -481,6 +138,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -489,6 +147,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); @@ -511,11 +171,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -524,6 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); @@ -536,6 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -544,6 +207,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -552,6 +216,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); @@ -566,13 +231,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(definition.ThingPreference); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Definition for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(definition.Actor.HasValue) @@ -592,6 +258,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); @@ -604,6 +271,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -612,6 +280,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -620,6 +289,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); @@ -634,6 +304,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); writer.WritePropertyName("thingPreference"u8); @@ -645,6 +316,279 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "citation": + if(!AllowedVersionsPerProperty["citation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("citation"u8); + + if(value is IEnumerable objectListCitation) + { + foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "example": + if(!AllowedVersionsPerProperty["example"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("example"u8); + + if(value is IEnumerable objectListExample) + { + foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("note"u8); + + if(value is IEnumerable objectListNote) + { + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Definition"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "citation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "example", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index f3f69c568..9242d2ad8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,137 @@ namespace CDP4JsonSerializer /// public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dependentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +188,7 @@ public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, I /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +196,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,13 +214,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -110,14 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -135,14 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -160,13 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -184,13 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "measurementscale": - var allowedVersionsForMeasurementScale = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMeasurementScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) { return; } @@ -208,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -233,13 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -257,13 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -281,13 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -310,131 +381,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) - { - throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.2.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.Iid); - writer.WritePropertyName("measurementScale"u8); - - if(dependentParameterTypeAssignment.MeasurementScale.HasValue) - { - writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(dependentParameterTypeAssignment.Actor.HasValue) - { - writer.WriteStringValue(dependentParameterTypeAssignment.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.Iid); - writer.WritePropertyName("measurementScale"u8); - - if(dependentParameterTypeAssignment.MeasurementScale.HasValue) - { - writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index 1df35a4f6..f44c6f3fe 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,395 +51,437 @@ namespace CDP4JsonSerializer public class DerivedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DerivedQuantityKind derivedQuantityKind) + { + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleScaleItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - if(value is IEnumerable objectListCategory) + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteOrderedItem(quantityKindFactorItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "defaultscale": - var allowedVersionsForDefaultScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("defaultScale"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleScaleItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - if(value is IEnumerable objectListDefinition) + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteOrderedItem(quantityKindFactorItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleScaleItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(quantityKindFactorItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedQuantityKind.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(derivedQuantityKind.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "possiblescale": - var allowedVersionsForPossibleScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); writer.WriteStartArray("possibleScale"u8); - if(value is IEnumerable objectListPossibleScale) + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStringValue(possibleScaleItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); break; - case "quantitydimensionsymbol": - var allowedVersionsForQuantityDimensionSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -446,77 +489,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "quantitykindfactor": - var allowedVersionsForQuantityKindFactor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForQuantityKindFactor.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("quantityKindFactor"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListQuantityKindFactor) + if(value is IEnumerable objectListAlias) { - foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteOrderedItem(quantityKindFactorItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) { - writer.WriteNullValue(); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } } - + + writer.WriteEndArray(); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -524,25 +543,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("defaultScale"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -550,411 +561,307 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedQuantityKind"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DerivedQuantityKind derivedQuantityKind) - { - throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(possibleScaleItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteOrderedItem(quantityKindFactorItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(derivedQuantityKind.Symbol); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(possibleScaleItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(quantityKindFactorItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(derivedQuantityKind.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("possibleScale"u8); - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPossibleScale) { - writer.WriteStringValue(excludedPersonItem); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + break; + case "quantitykindfactor": + if(!AllowedVersionsPerProperty["quantityKindFactor"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); writer.WriteStartArray("quantityKindFactor"u8); - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListQuantityKindFactor) { - writer.WriteOrderedItem(quantityKindFactorItem); + foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(derivedQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(derivedQuantityKind.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(derivedQuantityKind.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(derivedQuantityKind.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteOrderedItem(quantityKindFactorItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(derivedQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(derivedQuantityKind.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedQuantityKind"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKindFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index ecea0fcae..100c65783 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,317 +51,341 @@ namespace CDP4JsonSerializer public class DerivedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DerivedUnit derivedUnit) + { + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); - if(value is IEnumerable objectListAlias) + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteOrderedItem(unitFactorItem); } - + writer.WriteEndArray(); + break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteOrderedItem(unitFactorItem); } - + writer.WriteEndArray(); + break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(unitFactorItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedUnit.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(derivedUnit.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(unitFactorItem); } + writer.WriteEndArray(); + break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -368,49 +393,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -418,325 +429,248 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "unitfactor": - var allowedVersionsForUnitFactor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnitFactor.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("unitFactor"u8); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListUnitFactor) + if(value is IEnumerable objectListDefinition) { - foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteOrderedItem(unitFactorItem); + writer.WriteStringValue(definitionItem); } } writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DerivedUnit derivedUnit) - { - throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(definitionItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedUnit.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedUnit.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedUnit.ShortName); - writer.WriteStartArray("unitFactor"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteOrderedItem(unitFactorItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedUnit.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedUnit.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedUnit.ShortName); - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(unitFactorItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedUnit.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedUnit.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(derivedUnit.ThingPreference); - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(unitFactorItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DerivedUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(derivedUnit.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(derivedUnit.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "unitfactor": + if(!AllowedVersionsPerProperty["unitFactor"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(derivedUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(derivedUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(derivedUnit.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(derivedUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(derivedUnit.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(derivedUnit.ThingPreference); writer.WriteStartArray("unitFactor"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListUnitFactor) { - writer.WriteOrderedItem(unitFactorItem); + foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unitFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index 769a56402..f63fa3c49 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,206 @@ namespace CDP4JsonSerializer /// public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not DiagramCanvas diagramCanvas) + { + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramCanvas.Actor.HasValue) + { + writer.WriteStringValue(diagramCanvas.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +257,7 @@ public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +265,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "bounds": - var allowedVersionsForBounds = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForBounds.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) { return; } @@ -111,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -161,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "diagramelement": - var allowedVersionsForDiagramElement = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) { return; } @@ -186,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -261,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -286,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -311,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -336,13 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -365,192 +486,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not DiagramCanvas diagramCanvas) - { - throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramCanvas.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramCanvas.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramCanvas.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramCanvas.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramCanvas.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramCanvas.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramCanvas.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramCanvas for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(diagramCanvas.Actor.HasValue) - { - writer.WriteStringValue(diagramCanvas.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramCanvas.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramCanvas.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramCanvas.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramCanvas.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 54d41184c..bd83b5099 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,355 +51,352 @@ namespace CDP4JsonSerializer public class DiagramEdgeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramEdge.DepictedThing.Value); } else { writer.WriteNullValue(); } - break; - case "bounds": - var allowedVersionsForBounds = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForBounds.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } - writer.WriteStartArray("bounds"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListBounds) + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(localStyleItem); } - break; - case "depictedthing": - var allowedVersionsForDepictedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - if(!allowedVersionsForDepictedThing.Contains(requestedVersion)) + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(pointItem); } - writer.WritePropertyName("depictedThing"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramEdge.SharedStyle.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); break; - case "diagramelement": - var allowedVersionsForDiagramElement = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); - if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WriteStartArray("diagramElement"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); - if(value is IEnumerable objectListDiagramElement) + if(diagramEdge.DepictedThing.HasValue) { - foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStringValue(diagramEdge.DepictedThing.Value); } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(localStyleItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(pointItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramEdge.SharedStyle.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); break; - case "localstyle": - var allowedVersionsForLocalStyle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - if(!allowedVersionsForLocalStyle.Contains(requestedVersion)) + if(diagramEdge.Actor.HasValue) { - return; + writer.WriteStringValue(diagramEdge.Actor.Value); } - - writer.WriteStartArray("localStyle"u8); - - if(value is IEnumerable objectListLocalStyle) + else { - foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + writer.WriteNullValue(); } - - writer.WriteEndArray(); - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(diagramEdge.DepictedThing.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "point": - var allowedVersionsForPoint = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForPoint.Contains(requestedVersion)) + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("point"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); - if(value is IEnumerable objectListPoint) + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(pointItem); - } + writer.WriteStringValue(localStyleItem); } - + writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(pointItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(diagramEdge.SharedStyle.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); break; - case "sharedstyle": - var allowedVersionsForSharedStyle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForSharedStyle.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("sharedStyle"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -410,49 +408,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "source": - var allowedVersionsForSource = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSource.Contains(requestedVersion)) + case "bounds": + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("source"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) { - writer.WriteNullValue(); + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } } - + + writer.WriteEndArray(); break; - case "target": - var allowedVersionsForTarget = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTarget.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("target"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -460,23 +444,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "depictedthing": + if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("depictedThing"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -484,318 +462,268 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramEdge"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DiagramEdge diagramEdge) - { - throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + case "diagramelement": + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) { - writer.WriteStringValue(boundsItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramEdge.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); + writer.WriteStartArray("diagramElement"u8); - if(diagramEdge.DepictedThing.HasValue) - { - writer.WriteStringValue(diagramEdge.DepictedThing.Value); - } - else + if(value is IEnumerable objectListDiagramElement) { - writer.WriteNullValue(); + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } } - - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramElementItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(localStyleItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramEdge.Name); - writer.WriteStartArray("point"u8); - - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteOrderedItem(pointItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramEdge.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); - - if(diagramEdge.SharedStyle.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.SharedStyle.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("source"u8); - writer.WriteStringValue(diagramEdge.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(diagramEdge.Target); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + case "localstyle": + if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) { - writer.WriteStringValue(boundsItem); + return; } + writer.WriteStartArray("localStyle"u8); + + if(value is IEnumerable objectListLocalStyle) + { + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + } + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramEdge.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(diagramEdge.DepictedThing.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.DepictedThing.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramElementItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "point": + if(!AllowedVersionsPerProperty["point"].Contains(requestedVersion)) { - writer.WriteStringValue(localStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramEdge.Name); writer.WriteStartArray("point"u8); - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListPoint) { - writer.WriteOrderedItem(pointItem); + foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramEdge.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(diagramEdge.SharedStyle.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.SharedStyle.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("source"u8); - writer.WriteStringValue(diagramEdge.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(diagramEdge.Target); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramEdge.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramEdge for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "sharedstyle": + if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) + { + return; + } - if(diagramEdge.Actor.HasValue) + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + break; + case "source": + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) { - writer.WriteStringValue(boundsItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramEdge.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); - - if(diagramEdge.DepictedThing.HasValue) + writer.WritePropertyName("source"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.DepictedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "target": + if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("target"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(localStyleItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramEdge.Name); - writer.WriteStartArray("point"u8); - - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteOrderedItem(pointItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramEdge.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); - - if(diagramEdge.SharedStyle.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(diagramEdge.SharedStyle.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("source"u8); - writer.WriteStringValue(diagramEdge.Source); - writer.WritePropertyName("target"u8); - writer.WriteStringValue(diagramEdge.Target); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramEdge.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramEdge"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "point", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 246cec687..8c6f2971d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,109 +51,107 @@ namespace CDP4JsonSerializer public class DiagramObjectSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DiagramObject diagramObject) + { + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramObject.DepictedThing.Value); } else { writer.WriteNullValue(); } - break; - case "bounds": - var allowedVersionsForBounds = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForBounds.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } - writer.WriteStartArray("bounds"u8); - - if(value is IEnumerable objectListBounds) - { - foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - } - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "depictedthing": - var allowedVersionsForDepictedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - if(!allowedVersionsForDepictedThing.Contains(requestedVersion)) + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(localStyleItem); } - writer.WritePropertyName("depictedThing"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramObject.SharedStyle.Value); } else { @@ -160,249 +159,221 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "diagramelement": - var allowedVersionsForDiagramElement = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); - if(!allowedVersionsForDiagramElement.Contains(requestedVersion)) + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WriteStartArray("diagramElement"u8); - - if(value is IEnumerable objectListDiagramElement) - { - foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } - } - writer.WriteEndArray(); - break; - case "documentation": - var allowedVersionsForDocumentation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDocumentation.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("documentation"u8); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(diagramObject.DepictedThing.Value); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(localStyleItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(diagramObject.SharedStyle.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); break; - case "localstyle": - var allowedVersionsForLocalStyle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - if(!allowedVersionsForLocalStyle.Contains(requestedVersion)) + if(diagramObject.Actor.HasValue) { - return; + writer.WriteStringValue(diagramObject.Actor.Value); } - - writer.WriteStartArray("localStyle"u8); - - if(value is IEnumerable objectListLocalStyle) + else { - foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + writer.WriteNullValue(); } - - writer.WriteEndArray(); - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(boundsItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(diagramObject.DepictedThing.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("diagramElement"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramElementItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "resolution": - var allowedVersionsForResolution = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - if(!allowedVersionsForResolution.Contains(requestedVersion)) + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(localStyleItem); } - writer.WritePropertyName("resolution"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteStringValue(diagramObject.SharedStyle.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -410,24 +381,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "sharedstyle": - var allowedVersionsForSharedStyle = new List + case "bounds": + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("bounds"u8); - if(!allowedVersionsForSharedStyle.Contains(requestedVersion)) + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("sharedStyle"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,23 +417,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "depictedthing": + if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("depictedThing"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -459,108 +435,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramObject"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DiagramObject diagramObject) - { - throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); + case "diagramelement": + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) + { + return; + } - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDiagramElement) { - writer.WriteStringValue(boundsItem); + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramObject.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); + break; + case "documentation": + if(!AllowedVersionsPerProperty["documentation"].Contains(requestedVersion)) + { + return; + } - if(diagramObject.DepictedThing.HasValue) + writer.WritePropertyName("documentation"u8); + + if(value != null) { - writer.WriteStringValue(diagramObject.DepictedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramElementItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("documentation"u8); - writer.WriteStringValue(diagramObject.Documentation); writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(localStyleItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramObject.Name); - writer.WritePropertyName("resolution"u8); - writer.WriteNumberValue(diagramObject.Resolution); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramObject.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(diagramObject.SharedStyle.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(diagramObject.SharedStyle.Value); + writer.WriteStringValue((Guid)value); } else { @@ -568,185 +525,159 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + case "localstyle": + if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) { - writer.WriteStringValue(boundsItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramObject.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); + writer.WriteStartArray("localStyle"u8); - if(diagramObject.DepictedThing.HasValue) - { - writer.WriteStringValue(diagramObject.DepictedThing.Value); - } - else + if(value is IEnumerable objectListLocalStyle) { - writer.WriteNullValue(); + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } } - - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramElementItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("documentation"u8); - writer.WriteStringValue(diagramObject.Documentation); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(localStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramObject.Name); - writer.WritePropertyName("resolution"u8); - writer.WriteNumberValue(diagramObject.Resolution); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramObject.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); - - if(diagramObject.SharedStyle.HasValue) + + if(value != null) { - writer.WriteStringValue(diagramObject.SharedStyle.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramObject.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DiagramObject for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "resolution": + if(!AllowedVersionsPerProperty["resolution"].Contains(requestedVersion)) + { + return; + } - if(diagramObject.Actor.HasValue) + writer.WritePropertyName("resolution"u8); + + if(value != null) { - writer.WriteStringValue(diagramObject.Actor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(boundsItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(diagramObject.ClassKind.ToString()); - writer.WritePropertyName("depictedThing"u8); - - if(diagramObject.DepictedThing.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(diagramObject.DepictedThing.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + break; + case "sharedstyle": + if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramElementItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("documentation"u8); - writer.WriteStringValue(diagramObject.Documentation); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(localStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(diagramObject.Name); - writer.WritePropertyName("resolution"u8); - writer.WriteNumberValue(diagramObject.Resolution); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(diagramObject.RevisionNumber); - writer.WritePropertyName("sharedStyle"u8); - - if(diagramObject.SharedStyle.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(diagramObject.SharedStyle.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(diagramObject.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramObject"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "documentation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "resolution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index 150af9e1c..487b8d342 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,253 @@ namespace CDP4JsonSerializer /// public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not DomainFileStore domainFileStore) + { + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainFileStore.Actor.HasValue) + { + writer.WriteStringValue(domainFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +304,7 @@ public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +312,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +330,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -138,14 +366,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "file": - var allowedVersionsForFile = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFile.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) { return; } @@ -214,15 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "folder": - var allowedVersionsForFolder = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFolder.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) { return; } @@ -240,15 +438,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -266,15 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ishidden": - var allowedVersionsForIsHidden = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsHidden.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isHidden"].Contains(requestedVersion)) { return; } @@ -292,14 +474,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -317,15 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -343,15 +510,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -369,15 +528,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -395,13 +546,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -424,237 +569,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not DomainFileStore domainFileStore) - { - throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainFileStore.Iid); - writer.WritePropertyName("isHidden"u8); - writer.WriteBooleanValue(domainFileStore.IsHidden); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(domainFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainFileStore.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainFileStore.Iid); - writer.WritePropertyName("isHidden"u8); - writer.WriteBooleanValue(domainFileStore.IsHidden); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(domainFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainFileStore.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainFileStore.Iid); - writer.WritePropertyName("isHidden"u8); - writer.WriteBooleanValue(domainFileStore.IsHidden); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(domainFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainFileStore.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainFileStore.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DomainFileStore for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(domainFileStore.Actor.HasValue) - { - writer.WriteStringValue(domainFileStore.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainFileStore.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainFileStore.Iid); - writer.WritePropertyName("isHidden"u8); - writer.WriteBooleanValue(domainFileStore.IsHidden); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainFileStore.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(domainFileStore.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainFileStore.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainFileStore.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isHidden", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index 39729d22c..0b6e75b6d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,341 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) + { + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "domain": - var allowedVersionsForDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDomain.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("domain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDomain) + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("domain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(domainOfExpertiseGroup.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(domainOfExpertiseGroup.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,49 +393,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -444,299 +429,248 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertiseGroup"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) - { - throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) { - writer.WriteStringValue(domainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("domain"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDomain) { - writer.WriteStringValue(hyperLinkItem); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(definitionItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(domainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(domainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(domainOfExpertiseGroup.Actor.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(domainOfExpertiseGroup.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(domainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertiseGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ShortName); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertiseGroup"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index d5fe53e4e..27e14bd41 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,341 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not DomainOfExpertise domainOfExpertise) + { + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(domainOfExpertise.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(domainOfExpertise.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,49 +393,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -444,299 +447,230 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertise"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not DomainOfExpertise domainOfExpertise) - { - throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("definition"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(categoryItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(hyperLinkItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertise.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertise.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertise.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertise.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(excludedDomainItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertise.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertise.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertise.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertise.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertise.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertise.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertise.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertise.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainOfExpertise.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing DomainOfExpertise for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - if(domainOfExpertise.Actor.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(domainOfExpertise.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(domainOfExpertise.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(domainOfExpertise.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(domainOfExpertise.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(domainOfExpertise.ShortName); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(domainOfExpertise.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertise"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index 79cf4552d..dfb690303 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,560 +51,355 @@ namespace CDP4JsonSerializer public class ElementDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ElementDefinition elementDefinition) + { + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(containedElementItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListAlias) + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - if(value is IEnumerable objectListCategory) + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(parameterItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("parameterGroup"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterGroupItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(referencedElementItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); break; - case "containedelement": - var allowedVersionsForContainedElement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForContainedElement.Contains(requestedVersion)) + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("containedElement"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListContainedElement) + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedElementItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(containedElementItem); } + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(parameterItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("parameterGroup"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterGroupItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(referencedElementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(containedElementItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "organizationalparticipant": - var allowedVersionsForOrganizationalParticipant = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForOrganizationalParticipant.Contains(requestedVersion)) + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("organizationalParticipant"u8); - - if(value is IEnumerable objectListOrganizationalParticipant) - { - foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } - } - writer.WriteEndArray(); - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("owner"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "parameter": - var allowedVersionsForParameter = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForParameter.Contains(requestedVersion)) + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("parameter"u8); - - if(value is IEnumerable objectListParameter) - { - foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterItem); - } - } - writer.WriteEndArray(); - break; - case "parametergroup": - var allowedVersionsForParameterGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); - if(!allowedVersionsForParameterGroup.Contains(requestedVersion)) + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(organizationalParticipantItem); } - writer.WriteStartArray("parameterGroup"u8); - - if(value is IEnumerable objectListParameterGroup) - { - foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterGroupItem); - } - } - writer.WriteEndArray(); - break; - case "referencedelement": - var allowedVersionsForReferencedElement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - if(!allowedVersionsForReferencedElement.Contains(requestedVersion)) + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterItem); } - writer.WriteStartArray("referencedElement"u8); - - if(value is IEnumerable objectListReferencedElement) - { - foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedElementItem); - } - } - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("parameterGroup"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterGroupItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("referencedElement"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referencedElementItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + if(elementDefinition.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(elementDefinition.Actor.Value); } else { writer.WriteNullValue(); } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementDefinition"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ElementDefinition elementDefinition) - { - throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.0.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -612,6 +408,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("category"u8); foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) @@ -620,6 +417,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); writer.WriteStartArray("containedElement"u8); @@ -630,6 +428,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -638,377 +437,497 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + + writer.WriteStartArray("excludedDomain"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue(excludedDomainItem); } writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementDefinition.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementDefinition.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); + + writer.WriteStartArray("excludedPerson"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); - writer.WriteStartArray("parameterGroup"u8); + + writer.WriteStartArray("hyperLink"u8); - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterGroupItem); + writer.WriteStringValue(hyperLinkItem); } writer.WriteEndArray(); - writer.WriteStartArray("referencedElement"u8); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(referencedElementItem); + writer.WriteStringValue(organizationalParticipantItem); } writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementDefinition.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementDefinition.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.1.0"); - writer.WriteStartArray("alias"u8); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(parameterItem); } writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + + writer.WriteStartArray("parameterGroup"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(parameterGroupItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); + + writer.WriteStartArray("referencedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(containedElementItem); + writer.WriteStringValue(referencedElementItem); } writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("actor"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementDefinition.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementDefinition.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); + writer.WriteStartArray("alias"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(parameterItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterGroupItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referencedElement"u8); + writer.WriteStartArray("category"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListCategory) { - writer.WriteStringValue(referencedElementItem); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementDefinition.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementDefinition.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "containedelement": + if(!AllowedVersionsPerProperty["containedElement"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementDefinition.ClassKind.ToString()); writer.WriteStartArray("containedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListContainedElement) { - writer.WriteStringValue(containedElementItem); + foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } } - + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementDefinition.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementDefinition.Name); - writer.WriteStartArray("organizationalParticipant"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(organizationalParticipantItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("parameterGroup"u8); + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + break; + case "organizationalparticipant": + if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterGroupItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referencedElement"u8); + writer.WriteStartArray("organizationalParticipant"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListOrganizationalParticipant) { - writer.WriteStringValue(referencedElementItem); + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementDefinition.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementDefinition.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(elementDefinition.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ElementDefinition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } - if(elementDefinition.Actor.HasValue) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(elementDefinition.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "parameter": + if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("parameter"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameter) { - writer.WriteStringValue(categoryItem); + foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); - - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + break; + case "parametergroup": + if(!AllowedVersionsPerProperty["parameterGroup"].Contains(requestedVersion)) { - writer.WriteStringValue(containedElementItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("parameterGroup"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterGroup) { - writer.WriteStringValue(definitionItem); + foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "referencedelement": + if(!AllowedVersionsPerProperty["referencedElement"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("referencedElement"u8); - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListReferencedElement) { - writer.WriteStringValue(excludedPersonItem); + foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementDefinition.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementDefinition.Name); - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(organizationalParticipantItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); - - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(parameterItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterGroupItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referencedElement"u8); + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(referencedElementItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementDefinition.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementDefinition.ShortName); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(elementDefinition.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementDefinition"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 1653d0d9a..b2751cf4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,391 +51,425 @@ namespace CDP4JsonSerializer public class ElementUsageSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ElementUsage elementUsage) + { + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludeOption"u8); - if(value is IEnumerable objectListAlias) + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(excludeOptionItem); } - + writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - if(value is IEnumerable objectListCategory) + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(parameterOverrideItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "elementdefinition": - var allowedVersionsForElementDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludeOption"u8); - if(!allowedVersionsForElementDefinition.Contains(requestedVersion)) + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludeOptionItem); } - writer.WritePropertyName("elementDefinition"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(parameterOverrideItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludeoption": - var allowedVersionsForExcludeOption = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludeOption.Contains(requestedVersion)) + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - if(value is IEnumerable objectListExcludeOption) + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } - } - - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; + writer.WriteStringValue(excludeOptionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterOverrideItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(elementUsage.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(elementUsage.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "interfaceend": - var allowedVersionsForInterfaceEnd = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForInterfaceEnd.Contains(requestedVersion)) + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("interfaceEnd"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((InterfaceEndKind)value).ToString()); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludeOptionItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(parameterOverrideItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -446,51 +481,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "parameteroverride": - var allowedVersionsForParameterOverride = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterOverride.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("parameterOverride"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListParameterOverride) + if(value is IEnumerable objectListAlias) { - foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterOverrideItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -498,25 +535,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForShortName.Contains(requestedVersion)) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "elementdefinition": + if(!AllowedVersionsPerProperty["elementDefinition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("elementDefinition"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -524,403 +571,270 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue((string)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementUsage"); - } - } + writer.WriteStartArray("excludedPerson"u8); - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ElementUsage elementUsage) - { - throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeoption": + if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("elementDefinition"u8); - writer.WriteStringValue(elementUsage.ElementDefinition); writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludeOption) { - writer.WriteStringValue(excludeOptionItem); + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementUsage.Iid); - writer.WritePropertyName("interfaceEnd"u8); - writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementUsage.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(parameterOverrideItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementUsage.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementUsage.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("elementDefinition"u8); - writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "interfaceend": + if(!AllowedVersionsPerProperty["interfaceEnd"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("interfaceEnd"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((InterfaceEndKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludeOptionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementUsage.Iid); - writer.WritePropertyName("interfaceEnd"u8); - writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementUsage.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(parameterOverrideItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementUsage.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementUsage.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("elementDefinition"u8); - writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludeOptionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "parameteroverride": + if(!AllowedVersionsPerProperty["parameterOverride"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementUsage.Iid); - writer.WritePropertyName("interfaceEnd"u8); - writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementUsage.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementUsage.Owner); writer.WriteStartArray("parameterOverride"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterOverride) { - writer.WriteStringValue(parameterOverrideItem); + foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementUsage.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementUsage.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(elementUsage.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ElementUsage for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(elementUsage.Actor.HasValue) - { - writer.WriteStringValue(elementUsage.Actor.Value); - } - else + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("elementDefinition"u8); - writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludeOptionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(elementUsage.Iid); - writer.WritePropertyName("interfaceEnd"u8); - writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(elementUsage.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(parameterOverrideItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(elementUsage.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(elementUsage.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(elementUsage.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementUsage"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "interfaceEnd", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index 806e68b7f..917f19f7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not EmailAddress emailAddress) + { + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(emailAddress.Actor.HasValue) + { + writer.WriteStringValue(emailAddress.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,13 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -263,15 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -289,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "vcardtype": - var allowedVersionsForVcardType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForVcardType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not EmailAddress emailAddress) - { - throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(emailAddress.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(emailAddress.RevisionNumber); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(emailAddress.Value); - writer.WritePropertyName("vcardType"u8); - writer.WriteStringValue(emailAddress.VcardType.ToString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(emailAddress.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(emailAddress.RevisionNumber); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(emailAddress.Value); - writer.WritePropertyName("vcardType"u8); - writer.WriteStringValue(emailAddress.VcardType.ToString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(emailAddress.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(emailAddress.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(emailAddress.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(emailAddress.Value); - writer.WritePropertyName("vcardType"u8); - writer.WriteStringValue(emailAddress.VcardType.ToString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EmailAddress for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(emailAddress.Actor.HasValue) - { - writer.WriteStringValue(emailAddress.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(emailAddress.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(emailAddress.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(emailAddress.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(emailAddress.Value); - writer.WritePropertyName("vcardType"u8); - writer.WriteStringValue(emailAddress.VcardType.ToString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index b2c6ba21d..86eb793bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,197 @@ namespace CDP4JsonSerializer /// public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +248,7 @@ public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +256,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +274,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +292,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +346,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +364,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +382,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -261,14 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -286,14 +418,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +436,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "replyto": - var allowedVersionsForReplyTo = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReplyTo.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) { return; } @@ -336,14 +454,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,13 +472,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -390,189 +495,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) - { - throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(engineeringModelDataDiscussionItem.Actor.HasValue) - { - writer.WriteStringValue(engineeringModelDataDiscussionItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 58c900552..fc7c747ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,251 @@ namespace CDP4JsonSerializer /// public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not EngineeringModelDataNote engineeringModelDataNote) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataNote.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +302,7 @@ public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +346,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +364,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +382,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { return; } @@ -211,14 +418,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -236,14 +436,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -261,14 +454,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +472,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -311,14 +490,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -336,14 +508,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { return; } @@ -361,14 +526,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { return; } @@ -386,14 +544,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -411,13 +562,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -440,237 +585,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not EngineeringModelDataNote engineeringModelDataNote) - { - throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataNote.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) - { - writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataNote.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) - { - writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelDataNote.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelDataNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(engineeringModelDataNote.Actor.HasValue) - { - writer.WriteStringValue(engineeringModelDataNote.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(engineeringModelDataNote.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(engineeringModelDataNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelDataNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(engineeringModelDataNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) - { - writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelDataNote.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index e1215330c..307e41233 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,366 +51,378 @@ namespace CDP4JsonSerializer public class EngineeringModelSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not EngineeringModel engineeringModel) + { + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(commonFileStoreItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(iterationItem); } - break; - case "book": - var allowedVersionsForBook = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - if(!allowedVersionsForBook.Contains(requestedVersion)) + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(logEntryItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); writer.WriteStartArray("book"u8); - if(value is IEnumerable objectListBook) + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(bookItem); - } + writer.WriteOrderedItem(bookItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(commonFileStoreItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "commonfilestore": - var allowedVersionsForCommonFileStore = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForCommonFileStore.Contains(requestedVersion)) + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("commonFileStore"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); - if(value is IEnumerable objectListCommonFileStore) + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) { - foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } + writer.WriteStringValue(genericNoteItem); } - + writer.WriteEndArray(); - break; - case "engineeringmodelsetup": - var allowedVersionsForEngineeringModelSetup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - if(!allowedVersionsForEngineeringModelSetup.Contains(requestedVersion)) + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(iterationItem); } - writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(logEntryItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(modellingAnnotationItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); + writer.WriteStartArray("book"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(bookItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(commonFileStoreItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "genericnote": - var allowedVersionsForGenericNote = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("genericNote"u8); - if(!allowedVersionsForGenericNote.Contains(requestedVersion)) + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(genericNoteItem); } - writer.WriteStartArray("genericNote"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - if(value is IEnumerable objectListGenericNote) + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) { - foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(genericNoteItem); - } + writer.WriteStringValue(iterationItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(logEntryItem); + } - if(!allowedVersionsForIid.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(modellingAnnotationItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModel.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(engineeringModel.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "iteration": - var allowedVersionsForIteration = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("book"u8); - if(!allowedVersionsForIteration.Contains(requestedVersion)) + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(bookItem); } - writer.WriteStartArray("iteration"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - if(value is IEnumerable objectListIteration) + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) { - foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationItem); - } + writer.WriteStringValue(commonFileStoreItem); } - + writer.WriteEndArray(); - break; - case "lastmodifiedon": - var allowedVersionsForLastModifiedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForLastModifiedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "logentry": - var allowedVersionsForLogEntry = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); - if(!allowedVersionsForLogEntry.Contains(requestedVersion)) + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(genericNoteItem); } - writer.WriteStartArray("logEntry"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - if(value is IEnumerable objectListLogEntry) + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) { - foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStringValue(iterationItem); } - + writer.WriteEndArray(); - break; - case "modellingannotation": - var allowedVersionsForModellingAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - if(!allowedVersionsForModellingAnnotation.Contains(requestedVersion)) + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(logEntryItem); } + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); - if(value is IEnumerable objectListModellingAnnotation) + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modellingAnnotationItem); - } + writer.WriteStringValue(modellingAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { @@ -417,25 +430,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "book": + if(!AllowedVersionsPerProperty["book"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + writer.WriteStartArray("book"u8); + + if(value is IEnumerable objectListBook) + { + foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -443,23 +466,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List + case "commonfilestore": + if(!AllowedVersionsPerProperty["commonFileStore"].Contains(requestedVersion)) { - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("commonFileStore"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListCommonFileStore) + { + foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + } + + writer.WriteEndArray(); + break; + case "engineeringmodelsetup": + if(!AllowedVersionsPerProperty["engineeringModelSetup"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("engineeringModelSetup"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -467,331 +502,231 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModel"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not EngineeringModel engineeringModel) - { - throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelSetup"u8); - writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(iterationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(logEntryItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModel.RevisionNumber); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.1.0"); - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteOrderedItem(bookItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(commonFileStoreItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelSetup"u8); - writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "genericnote": + if(!AllowedVersionsPerProperty["genericNote"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("genericNote"u8); - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGenericNote) { - writer.WriteStringValue(excludedPersonItem); + foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(genericNoteItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(iterationItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(logEntryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("modellingAnnotation"u8); - - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + break; + case "iteration": + if(!AllowedVersionsPerProperty["iteration"].Contains(requestedVersion)) { - writer.WriteStringValue(modellingAnnotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModel.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.2.0"); - writer.WriteStartArray("book"u8); + writer.WriteStartArray("iteration"u8); - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListIteration) { - writer.WriteOrderedItem(bookItem); + foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + break; + case "lastmodifiedon": + if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(commonFileStoreItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelSetup"u8); - writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + break; + case "logentry": + if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) { - writer.WriteStringValue(genericNoteItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); + writer.WriteStartArray("logEntry"u8); - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListLogEntry) { - writer.WriteStringValue(iterationItem); + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + break; + case "modellingannotation": + if(!AllowedVersionsPerProperty["modellingAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(logEntryItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("modellingAnnotation"u8); - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListModellingAnnotation) { - writer.WriteStringValue(modellingAnnotationItem); + foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModel.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModel.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModel for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(engineeringModel.Actor.HasValue) - { - writer.WriteStringValue(engineeringModel.Actor.Value); - } - else + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteOrderedItem(bookItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(commonFileStoreItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelSetup"u8); - writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(genericNoteItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(iterationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(logEntryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("modellingAnnotation"u8); - - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(modellingAnnotationItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModel.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModel.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModel"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "book", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "commonFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "genericNote", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iteration", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modellingAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index a26486065..7ee57ff94 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,543 +51,563 @@ namespace CDP4JsonSerializer public class EngineeringModelSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "activedomain": - var allowedVersionsForActiveDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActiveDomain.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); writer.WriteStartArray("activeDomain"u8); - if(value is IEnumerable objectListActiveDomain) + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } + writer.WriteStringValue(activeDomainItem); } - + writer.WriteEndArray(); - break; - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(iterationSetupItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); - if(value is IEnumerable objectListAlias) + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(participantItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("requiredRdl"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requiredRdlItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); break; - case "defaultorganizationalparticipant": - var allowedVersionsForDefaultOrganizationalParticipant = new List - { - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); + writer.WriteStartArray("activeDomain"u8); - if(!allowedVersionsForDefaultOrganizationalParticipant.Contains(requestedVersion)) + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(activeDomainItem); } - writer.WritePropertyName("defaultOrganizationalParticipant"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(aliasItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + writer.WriteEndArray(); - break; - case "engineeringmodeliid": - var allowedVersionsForEngineeringModelIid = new List + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); - if(!allowedVersionsForEngineeringModelIid.Contains(requestedVersion)) + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requiredRdlItem); } - writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); + writer.WriteStartArray("activeDomain"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(activeDomainItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) { - return; + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(iterationSetupItem); } - break; - case "iterationsetup": - var allowedVersionsForIterationSetup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); - if(!allowedVersionsForIterationSetup.Contains(requestedVersion)) + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(organizationalParticipantItem); } - writer.WriteStartArray("iterationSetup"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("participant"u8); - if(value is IEnumerable objectListIterationSetup) + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) { - foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationSetupItem); - } + writer.WriteStringValue(participantItem); } - + writer.WriteEndArray(); - break; - case "kind": - var allowedVersionsForKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("requiredRdl"u8); - if(!allowedVersionsForKind.Contains(requestedVersion)) + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requiredRdlItem); } - writer.WritePropertyName("kind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { - writer.WriteStringValue(((EngineeringModelKind)value).ToString()); + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); + writer.WriteStartArray("activeDomain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(activeDomainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("actor"u8); + + if(engineeringModelSetup.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(engineeringModelSetup.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); } else { writer.WriteNullValue(); } - break; - case "organizationalparticipant": - var allowedVersionsForOrganizationalParticipant = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForOrganizationalParticipant.Contains(requestedVersion)) + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("organizationalParticipant"u8); - - if(value is IEnumerable objectListOrganizationalParticipant) - { - foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } - } - writer.WriteEndArray(); - break; - case "participant": - var allowedVersionsForParticipant = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForParticipant.Contains(requestedVersion)) + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("participant"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListParticipant) + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "requiredrdl": - var allowedVersionsForRequiredRdl = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("requiredRdl"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - if(value is IEnumerable objectListRequiredRdl) + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) { - foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requiredRdlItem); - } + writer.WriteStringValue(iterationSetupItem); } - + writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(organizationalParticipantItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(participantItem); } - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requiredRdlItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); break; - case "sourceengineeringmodelsetupiid": - var allowedVersionsForSourceEngineeringModelSetupIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForSourceEngineeringModelSetupIid.Contains(requestedVersion)) - { - return; + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "activedomain": + if(!AllowedVersionsPerProperty["activeDomain"].Contains(requestedVersion)) + { + return; } - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + writer.WriteStartArray("activeDomain"u8); + + if(value is IEnumerable objectListActiveDomain) + { + foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); if(value != null) { @@ -598,25 +619,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "studyphase": - var allowedVersionsForStudyPhase = new List + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForStudyPhase.Contains(requestedVersion)) + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("studyPhase"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((StudyPhaseKind)value).ToString()); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -624,23 +655,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "defaultorganizationalparticipant": + if(!AllowedVersionsPerProperty["defaultOrganizationalParticipant"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -648,493 +673,364 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelSetup"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not EngineeringModelSetup engineeringModelSetup) - { - throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.0.0"); - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(activeDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("definition"u8); - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(aliasItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "engineeringmodeliid": + if(!AllowedVersionsPerProperty["engineeringModelIid"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("engineeringModelIid"u8); - writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(iterationSetupItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(participantItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("requiredRdl"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(requiredRdlItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(engineeringModelSetup.ShortName); - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) - { - writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); - } - else + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WritePropertyName("studyPhase"u8); - writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.1.0"); - writer.WriteStartArray("activeDomain"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(activeDomainItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelIid"u8); - writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + break; + case "iterationsetup": + if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) { - writer.WriteStringValue(iterationSetupItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("participant"u8); + writer.WriteStartArray("iterationSetup"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListIterationSetup) { - writer.WriteStringValue(participantItem); + foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + break; + case "kind": + if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) { - writer.WriteStringValue(requiredRdlItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(engineeringModelSetup.ShortName); - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + writer.WritePropertyName("kind"u8); + + if(value != null) { - writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + writer.WriteStringValue(((EngineeringModelKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WritePropertyName("studyPhase"u8); - writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.2.0"); - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WritePropertyName("defaultOrganizationalParticipant"u8); - - if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelIid"u8); - writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "organizationalparticipant": + if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); + writer.WriteStartArray("organizationalParticipant"u8); - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListOrganizationalParticipant) { - writer.WriteStringValue(iterationSetupItem); + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + break; + case "participant": + if(!AllowedVersionsPerProperty["participant"].Contains(requestedVersion)) { - writer.WriteStringValue(organizationalParticipantItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("participant"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParticipant) { - writer.WriteStringValue(participantItem); + foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) { - writer.WriteStringValue(requiredRdlItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(engineeringModelSetup.ShortName); - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + writer.WriteStartArray("requiredRdl"u8); - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) - { - writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); - } - else + if(value is IEnumerable objectListRequiredRdl) { - writer.WriteNullValue(); + foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } } - - writer.WritePropertyName("studyPhase"u8); - writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelSetup.ThingPreference); + + writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EngineeringModelSetup for Version 1.3.0"); - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(activeDomainItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("actor"u8); - - if(engineeringModelSetup.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(engineeringModelSetup.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WritePropertyName("defaultOrganizationalParticipant"u8); - - if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("engineeringModelIid"u8); - writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceengineeringmodelsetupiid": + if(!AllowedVersionsPerProperty["sourceEngineeringModelSetupIid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + break; + case "studyphase": + if(!AllowedVersionsPerProperty["studyPhase"].Contains(requestedVersion)) { - writer.WriteStringValue(iterationSetupItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("studyPhase"u8); + + if(value != null) { - writer.WriteStringValue(organizationalParticipantItem); + writer.WriteStringValue(((StudyPhaseKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(participantItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(requiredRdlItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(engineeringModelSetup.ShortName); - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("studyPhase"u8); - writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(engineeringModelSetup.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelSetup"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "activeDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOrganizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "participant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceEngineeringModelSetupIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "studyPhase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 17bfcb6e1..64c281224 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,369 +51,393 @@ namespace CDP4JsonSerializer public class EnumerationParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListAlias) + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "allowmultiselect": - var allowedVersionsForAllowMultiSelect = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAllowMultiSelect.Contains(requestedVersion)) + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteOrderedItem(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(valueDefinitionItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(enumerationParameterType.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(enumerationParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "name": - var allowedVersionsForName = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -420,25 +445,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "allowmultiselect": + if(!AllowedVersionsPerProperty["allowMultiSelect"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("allowMultiSelect"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -446,25 +481,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "symbol": - var allowedVersionsForSymbol = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,397 +517,269 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); break; - case "valuedefinition": - var allowedVersionsForValueDefinition = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("valueDefinition"u8); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListValueDefinition) + if(value is IEnumerable objectListHyperLink) { - foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteOrderedItem(valueDefinitionItem); + writer.WriteStringValue(hyperLinkItem); } } writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); - } - } + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not EnumerationParameterType enumerationParameterType) - { - throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("allowMultiSelect"u8); - writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(enumerationParameterType.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(enumerationParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(enumerationParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(enumerationParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(valueDefinitionItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("allowMultiSelect"u8); - writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(enumerationParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(enumerationParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(enumerationParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(enumerationParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(valueDefinitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("allowMultiSelect"u8); - writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(enumerationParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(enumerationParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(enumerationParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(enumerationParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(enumerationParameterType.ThingPreference); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteOrderedItem(valueDefinitionItem); + return; } - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(enumerationParameterType.Actor.HasValue) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(enumerationParameterType.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("allowMultiSelect"u8); - writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(enumerationParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(enumerationParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(enumerationParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(enumerationParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(enumerationParameterType.ThingPreference); writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListValueDefinition) { - writer.WriteOrderedItem(valueDefinitionItem); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "allowMultiSelect", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 03c22ebbd..ccb846988 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,354 +50,6 @@ namespace CDP4JsonSerializer /// public class EnumerationValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationValueDefinition"); - } - } - /// /// Serializes a into an /// @@ -423,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -432,6 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -442,6 +96,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -450,6 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); writer.WritePropertyName("name"u8); @@ -460,7 +116,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationValueDefinition.ShortName); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -469,6 +125,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -479,6 +136,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -487,6 +145,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -495,6 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -503,6 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -515,7 +176,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationValueDefinition.ShortName); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -524,6 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -534,6 +196,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -542,6 +205,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -550,6 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -558,6 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -572,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationValueDefinition.ThingPreference); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing EnumerationValueDefinition for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(enumerationValueDefinition.Actor.HasValue) @@ -592,6 +258,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -602,6 +269,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -610,6 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -618,6 +287,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -626,6 +296,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -645,6 +316,279 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationValueDefinition"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index 53ec45716..7efaec894 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,185 @@ namespace CDP4JsonSerializer /// public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(exclusiveOrExpression.Actor.HasValue) + { + writer.WriteStringValue(exclusiveOrExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +236,7 @@ public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerial /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +298,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +316,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +334,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +352,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +370,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - var allowedVersionsForTerm = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTerm.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) { return; } @@ -265,13 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -294,173 +411,20 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ExclusiveOrExpression exclusiveOrExpression) - { - throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(exclusiveOrExpression.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(exclusiveOrExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(exclusiveOrExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(exclusiveOrExpression.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ExclusiveOrExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(exclusiveOrExpression.Actor.HasValue) - { - writer.WriteStringValue(exclusiveOrExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(exclusiveOrExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(exclusiveOrExpression.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 90f4cc197..111625268 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,269 @@ namespace CDP4JsonSerializer /// public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(externalIdentifierMap.Actor.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +320,7 @@ public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerial /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +346,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +364,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "correspondence": - var allowedVersionsForCorrespondence = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCorrespondence.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["correspondence"].Contains(requestedVersion)) { return; } @@ -138,14 +382,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +418,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "externalformat": - var allowedVersionsForExternalFormat = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExternalFormat.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["externalFormat"].Contains(requestedVersion)) { return; } @@ -214,15 +436,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externalmodelname": - var allowedVersionsForExternalModelName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExternalModelName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["externalModelName"].Contains(requestedVersion)) { return; } @@ -240,15 +454,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externaltoolname": - var allowedVersionsForExternalToolName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExternalToolName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["externalToolName"].Contains(requestedVersion)) { return; } @@ -266,15 +472,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externaltoolversion": - var allowedVersionsForExternalToolVersion = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExternalToolVersion.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["externalToolVersion"].Contains(requestedVersion)) { return; } @@ -291,16 +489,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -318,14 +508,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -343,15 +526,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -369,15 +544,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -395,15 +562,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -421,13 +580,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -450,257 +603,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ExternalIdentifierMap externalIdentifierMap) - { - throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalFormat"u8); - - if(externalIdentifierMap.ExternalFormat.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("externalModelName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalModelName); - writer.WritePropertyName("externalToolName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolName); - writer.WritePropertyName("externalToolVersion"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(externalIdentifierMap.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(externalIdentifierMap.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(externalIdentifierMap.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalFormat"u8); - - if(externalIdentifierMap.ExternalFormat.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("externalModelName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalModelName); - writer.WritePropertyName("externalToolName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolName); - writer.WritePropertyName("externalToolVersion"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(externalIdentifierMap.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(externalIdentifierMap.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(externalIdentifierMap.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalFormat"u8); - - if(externalIdentifierMap.ExternalFormat.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("externalModelName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalModelName); - writer.WritePropertyName("externalToolName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolName); - writer.WritePropertyName("externalToolVersion"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(externalIdentifierMap.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(externalIdentifierMap.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(externalIdentifierMap.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(externalIdentifierMap.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ExternalIdentifierMap for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(externalIdentifierMap.Actor.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalFormat"u8); - - if(externalIdentifierMap.ExternalFormat.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("externalModelName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalModelName); - writer.WritePropertyName("externalToolName"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolName); - writer.WritePropertyName("externalToolVersion"u8); - writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(externalIdentifierMap.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(externalIdentifierMap.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(externalIdentifierMap.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(externalIdentifierMap.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "correspondence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalFormat", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalModelName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolVersion", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 3fe0cb979..3685cd366 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,261 @@ namespace CDP4JsonSerializer /// public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not FileRevision fileRevision) + { + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileRevision.Actor.HasValue) + { + writer.WriteStringValue(fileRevision.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +312,7 @@ public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +320,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +338,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +356,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containingfolder": - var allowedVersionsForContainingFolder = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContainingFolder.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) { return; } @@ -138,15 +374,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "contenthash": - var allowedVersionsForContentHash = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContentHash.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["contentHash"].Contains(requestedVersion)) { return; } @@ -163,16 +391,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -190,15 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "creator": - var allowedVersionsForCreator = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreator.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) { return; } @@ -216,14 +428,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -241,14 +446,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -266,15 +464,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "filetype": - var allowedVersionsForFileType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFileType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) { return; } @@ -292,15 +482,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -318,14 +500,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -343,15 +518,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -369,15 +536,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -395,13 +554,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -424,249 +577,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not FileRevision fileRevision) - { - throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileRevision.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(fileRevision.ContainingFolder.HasValue) - { - writer.WriteStringValue(fileRevision.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("contentHash"u8); - writer.WriteStringValue(fileRevision.ContentHash); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(fileTypeItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileRevision.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileRevision.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileRevision.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileRevision.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(fileRevision.ContainingFolder.HasValue) - { - writer.WriteStringValue(fileRevision.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("contentHash"u8); - writer.WriteStringValue(fileRevision.ContentHash); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(fileTypeItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileRevision.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileRevision.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileRevision.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileRevision.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(fileRevision.ContainingFolder.HasValue) - { - writer.WriteStringValue(fileRevision.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("contentHash"u8); - writer.WriteStringValue(fileRevision.ContentHash); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(fileTypeItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileRevision.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileRevision.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileRevision.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(fileRevision.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing FileRevision for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(fileRevision.Actor.HasValue) - { - writer.WriteStringValue(fileRevision.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileRevision.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(fileRevision.ContainingFolder.HasValue) - { - writer.WriteStringValue(fileRevision.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("contentHash"u8); - writer.WriteStringValue(fileRevision.ContentHash); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(fileTypeItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileRevision.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileRevision.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileRevision.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(fileRevision.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "contentHash", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 402554d07..0de93fab2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,328 +50,6 @@ namespace CDP4JsonSerializer /// public class FileSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) - { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "filerevision": - var allowedVersionsForFileRevision = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFileRevision.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("fileRevision"u8); - - if(value is IEnumerable objectListFileRevision) - { - foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileRevisionItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "lockedby": - var allowedVersionsForLockedBy = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLockedBy.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("lockedBy"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("owner"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the File"); - } - } - /// /// Serializes a into an /// @@ -397,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing File for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -406,6 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); writer.WriteStartArray("fileRevision"u8); @@ -416,6 +96,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); @@ -435,7 +116,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(file.RevisionNumber); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing File for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -444,6 +125,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -454,6 +136,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -462,6 +145,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -470,6 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); @@ -491,7 +176,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(file.RevisionNumber); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing File for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -500,6 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -510,6 +196,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -518,6 +205,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -526,6 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); @@ -549,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(file.ThingPreference); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing File for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(file.Actor.HasValue) @@ -569,6 +258,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -579,6 +269,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -587,6 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -595,6 +287,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); @@ -623,6 +316,260 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filerevision": + if(!AllowedVersionsPerProperty["fileRevision"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileRevision"u8); + + if(value is IEnumerable objectListFileRevision) + { + foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lockedby": + if(!AllowedVersionsPerProperty["lockedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lockedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the File"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileRevision", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lockedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 71b13359f..abb0ef315 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,292 +51,349 @@ namespace CDP4JsonSerializer public class FileTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not FileType fileType) + { + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "extension": - var allowedVersionsForExtension = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExtension.Contains(requestedVersion)) + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("extension"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileType.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(fileType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("isDeprecated"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue((Guid)value); } else { @@ -343,50 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -394,71 +455,67 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNumberValue((int)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) { - return; + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - - writer.WritePropertyName("shortName"u8); - if(value != null) + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue((string)value); + return; } - else + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteNullValue(); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "extension": + if(!AllowedVersionsPerProperty["extension"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("extension"u8); if(value != null) { @@ -470,307 +527,177 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the FileType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not FileType fileType) - { - throw new ArgumentException("The thing shall be a FileType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("extension"u8); - writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(fileType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(fileType.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("extension"u8); - writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(fileType.IsDeprecated); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(fileType.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("extension"u8); - writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(fileType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileType.Name); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(fileType.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(fileType.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing FileType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(fileType.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(fileType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("extension"u8); - writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(fileType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(fileType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(fileType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(fileType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(fileType.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(fileType.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "extension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index fa69502d8..084799a73 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,225 @@ namespace CDP4JsonSerializer /// public class FolderSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Folder folder) + { + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(folder.Actor.HasValue) + { + writer.WriteStringValue(folder.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +276,7 @@ public class FolderSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +284,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +302,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +320,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containingfolder": - var allowedVersionsForContainingFolder = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContainingFolder.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) { return; } @@ -138,15 +338,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -164,15 +356,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "creator": - var allowedVersionsForCreator = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreator.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) { return; } @@ -190,14 +374,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -215,14 +392,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -240,15 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -266,14 +428,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -291,15 +446,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -317,15 +464,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -343,15 +482,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -369,13 +500,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -398,217 +523,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Folder folder) - { - throw new ArgumentException("The thing shall be a Folder", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(folder.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(folder.ContainingFolder.HasValue) - { - writer.WriteStringValue(folder.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(folder.Creator); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(folder.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(folder.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(folder.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(folder.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(folder.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(folder.ContainingFolder.HasValue) - { - writer.WriteStringValue(folder.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(folder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(folder.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(folder.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(folder.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(folder.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(folder.ContainingFolder.HasValue) - { - writer.WriteStringValue(folder.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(folder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(folder.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(folder.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(folder.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(folder.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Folder for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(folder.Actor.HasValue) - { - writer.WriteStringValue(folder.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(folder.ClassKind.ToString()); - writer.WritePropertyName("containingFolder"u8); - - if(folder.ContainingFolder.HasValue) - { - writer.WriteStringValue(folder.ContainingFolder.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("creator"u8); - writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(folder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(folder.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(folder.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(folder.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(folder.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index b6bdf9a64..8574105e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,377 @@ namespace CDP4JsonSerializer public class GlossarySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not Glossary glossary) + { + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - if(value is IEnumerable objectListAlias) + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(termItem); } - + writer.WriteEndArray(); + break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - if(value is IEnumerable objectListDefinition) + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(termItem); } - + writer.WriteEndArray(); + break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(termItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(glossary.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(glossary.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(termItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,75 +429,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "term": - var allowedVersionsForTerm = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTerm.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("term"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListTerm) + if(value is IEnumerable objectListCategory) { - foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(termItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -470,331 +483,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Glossary"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Glossary glossary) - { - throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(glossary.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(glossary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(glossary.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(glossary.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(glossary.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(termItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(excludedDomainItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(glossary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(glossary.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(glossary.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(glossary.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(termItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(glossary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(glossary.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(glossary.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(glossary.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(termItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(glossary.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Glossary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(glossary.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(glossary.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("term"u8); - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListTerm) { - writer.WriteStringValue(excludedPersonItem); + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(glossary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(glossary.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(glossary.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(glossary.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(termItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(glossary.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Glossary"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 6d418939f..0fa9e943c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,260 @@ namespace CDP4JsonSerializer /// public class GoalSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(goal.Actor.HasValue) + { + writer.WriteStringValue(goal.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +311,7 @@ public class GoalSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "alias": - var allowedVersionsForAlias = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } @@ -111,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -136,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -161,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - var allowedVersionsForDefinition = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } @@ -186,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } @@ -261,14 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +481,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +499,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -336,14 +517,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,14 +535,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +553,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,240 +576,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Goal goal) - { - throw new ArgumentException("The thing shall be a Goal", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(goal.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(goal.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(goal.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(goal.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(goal.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(goal.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(goal.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(goal.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(goal.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Goal for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(goal.Actor.HasValue) - { - writer.WriteStringValue(goal.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(goal.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(goal.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(goal.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(goal.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(goal.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 13174fe29..d8d7d1034 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(hyperLink.Actor.HasValue) + { + writer.WriteStringValue(hyperLink.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -138,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -240,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -315,15 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "uri": - var allowedVersionsForUri = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUri.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["uri"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not HyperLink hyperLink) - { - throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(hyperLink.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(hyperLink.Content); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(hyperLink.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(hyperLink.LanguageCode); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(hyperLink.RevisionNumber); - writer.WritePropertyName("uri"u8); - writer.WriteStringValue(hyperLink.Uri); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(hyperLink.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(hyperLink.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(hyperLink.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(hyperLink.RevisionNumber); - writer.WritePropertyName("uri"u8); - writer.WriteStringValue(hyperLink.Uri); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(hyperLink.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(hyperLink.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(hyperLink.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(hyperLink.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(hyperLink.ThingPreference); - writer.WritePropertyName("uri"u8); - writer.WriteStringValue(hyperLink.Uri); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing HyperLink for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(hyperLink.Actor.HasValue) - { - writer.WriteStringValue(hyperLink.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(hyperLink.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(hyperLink.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(hyperLink.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(hyperLink.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(hyperLink.ThingPreference); - writer.WritePropertyName("uri"u8); - writer.WriteStringValue(hyperLink.Uri); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "uri", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index e5921d733..2c602e0b1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not IdCorrespondence idCorrespondence) + { + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(idCorrespondence.Actor.HasValue) + { + writer.WriteStringValue(idCorrespondence.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "externalid": - var allowedVersionsForExternalId = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExternalId.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["externalId"].Contains(requestedVersion)) { return; } @@ -188,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "internalthing": - var allowedVersionsForInternalThing = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForInternalThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["internalThing"].Contains(requestedVersion)) { return; } @@ -240,14 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not IdCorrespondence idCorrespondence) - { - throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WritePropertyName("externalId"u8); - writer.WriteStringValue(idCorrespondence.ExternalId); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(idCorrespondence.Iid); - writer.WritePropertyName("internalThing"u8); - writer.WriteStringValue(idCorrespondence.InternalThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(idCorrespondence.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalId"u8); - writer.WriteStringValue(idCorrespondence.ExternalId); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(idCorrespondence.Iid); - writer.WritePropertyName("internalThing"u8); - writer.WriteStringValue(idCorrespondence.InternalThing); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(idCorrespondence.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalId"u8); - writer.WriteStringValue(idCorrespondence.ExternalId); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(idCorrespondence.Iid); - writer.WritePropertyName("internalThing"u8); - writer.WriteStringValue(idCorrespondence.InternalThing); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(idCorrespondence.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(idCorrespondence.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing IdCorrespondence for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(idCorrespondence.Actor.HasValue) - { - writer.WriteStringValue(idCorrespondence.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("externalId"u8); - writer.WriteStringValue(idCorrespondence.ExternalId); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(idCorrespondence.Iid); - writer.WritePropertyName("internalThing"u8); - writer.WriteStringValue(idCorrespondence.InternalThing); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(idCorrespondence.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(idCorrespondence.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalId", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "internalThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index ef20fd8f1..0ba05cad9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,137 @@ namespace CDP4JsonSerializer /// public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(independentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +188,7 @@ public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +196,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,13 +214,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -110,14 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -135,14 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -160,13 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -184,13 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "measurementscale": - var allowedVersionsForMeasurementScale = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMeasurementScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) { return; } @@ -208,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -233,13 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -257,13 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -281,13 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -310,131 +381,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) - { - throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.2.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(independentParameterTypeAssignment.Iid); - writer.WritePropertyName("measurementScale"u8); - - if(independentParameterTypeAssignment.MeasurementScale.HasValue) - { - writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(independentParameterTypeAssignment.Actor.HasValue) - { - writer.WriteStringValue(independentParameterTypeAssignment.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(independentParameterTypeAssignment.Iid); - writer.WritePropertyName("measurementScale"u8); - - if(independentParameterTypeAssignment.MeasurementScale.HasValue) - { - writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 3dfd5bc22..6fa8d528c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,370 +51,441 @@ namespace CDP4JsonSerializer public class IntervalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not IntervalScale intervalScale) + { + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(mappingToReferenceScaleItem); } - break; - case "ismaximuminclusive": - var allowedVersionsForIsMaximumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(intervalScale.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(intervalScale.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isminimuminclusive": - var allowedVersionsForIsMinimumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "mappingtoreferencescale": - var allowedVersionsForMappingToReferenceScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("mappingToReferenceScale"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListMappingToReferenceScale) + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "maximumpermissiblevalue": - var allowedVersionsForMaximumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(mappingToReferenceScaleItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "minimumpermissiblevalue": - var allowedVersionsForMinimumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -421,50 +493,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,103 +529,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "negativevalueconnotation": - var allowedVersionsForNegativeValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("negativeValueConnotation"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "numberset": - var allowedVersionsForNumberSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) { - return; + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - - writer.WritePropertyName("numberSet"u8); - if(value != null) - { - writer.WriteStringValue(((NumberSetKind)value).ToString()); - } - else + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "positivevalueconnotation": - var allowedVersionsForPositiveValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) { - return; + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - - writer.WritePropertyName("positiveValueConnotation"u8); - if(value != null) + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue((string)value); + return; } - else + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) { - writer.WriteNullValue(); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + + writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -576,25 +619,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -602,23 +637,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -626,25 +655,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("unit"u8); + writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteBooleanValue((bool)value); } else { @@ -652,421 +673,275 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "valuedefinition": - var allowedVersionsForValueDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("valueDefinition"u8); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListValueDefinition) + if(value is IEnumerable objectListMappingToReferenceScale) { - foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue(mappingToReferenceScaleItem); } } writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not IntervalScale intervalScale) - { - throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(intervalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(intervalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MaximumPermissibleValue); writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MinimumPermissibleValue); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(intervalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(intervalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(intervalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(intervalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(intervalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(intervalScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(intervalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(intervalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(intervalScale.Name); writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(intervalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(intervalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(intervalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(intervalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(intervalScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("numberSet"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((NumberSetKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(intervalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(intervalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(intervalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(intervalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(intervalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(intervalScale.PositiveValueConnotation); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(intervalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(intervalScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(intervalScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing IntervalScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(intervalScale.Actor.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(intervalScale.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("unit"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(intervalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(intervalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(intervalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(intervalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(intervalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(intervalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(intervalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(intervalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(intervalScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(intervalScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(intervalScale.Unit); writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListValueDefinition) { - writer.WriteStringValue(valueDefinitionItem); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index 618c3355b..09ac4f3a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,789 +51,613 @@ namespace CDP4JsonSerializer public class IterationSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not Iteration iteration) + { + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(actualFiniteStateListItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(iteration.DefaultOption.Value); } else { writer.WriteNullValue(); } - break; - case "actualfinitestatelist": - var allowedVersionsForActualFiniteStateList = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("domainFileStore"u8); - if(!allowedVersionsForActualFiniteStateList.Contains(requestedVersion)) + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainFileStoreItem); } - writer.WriteStartArray("actualFiniteStateList"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); - if(value is IEnumerable objectListActualFiniteStateList) + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) { - foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualFiniteStateListItem); - } + writer.WriteStringValue(elementItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("externalIdentifierMap"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(externalIdentifierMapItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(optionItem); } - break; - case "defaultoption": - var allowedVersionsForDefaultOption = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); - if(!allowedVersionsForDefaultOption.Contains(requestedVersion)) + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleFiniteStateListItem); } - writer.WritePropertyName("defaultOption"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(publicationItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(relationshipItem); } - break; - case "diagramcanvas": - var allowedVersionsForDiagramCanvas = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); - if(!allowedVersionsForDiagramCanvas.Contains(requestedVersion)) + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requirementsSpecificationItem); } - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - if(value is IEnumerable objectListDiagramCanvas) + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) { - foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramCanvasItem); - } + writer.WriteStringValue(ruleVerificationListItem); } - + writer.WriteEndArray(); - break; - case "domainfilestore": - var allowedVersionsForDomainFileStore = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("sourceIterationIid"u8); - if(!allowedVersionsForDomainFileStore.Contains(requestedVersion)) + if(iteration.SourceIterationIid.HasValue) { - return; + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("domainFileStore"u8); + writer.WritePropertyName("topElement"u8); - if(value is IEnumerable objectListDomainFileStore) + if(iteration.TopElement.HasValue) { - foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainFileStoreItem); - } + writer.WriteStringValue(iteration.TopElement.Value); } - - writer.WriteEndArray(); - break; - case "element": - var allowedVersionsForElement = new List + else { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - if(!allowedVersionsForElement.Contains(requestedVersion)) + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(actualFiniteStateListItem); } - writer.WriteStartArray("element"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); - if(value is IEnumerable objectListElement) + if(iteration.DefaultOption.HasValue) { - foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(elementItem); - } + writer.WriteStringValue(iteration.DefaultOption.Value); } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(diagramCanvasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(domainFileStoreItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("element"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(elementItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "externalidentifiermap": - var allowedVersionsForExternalIdentifierMap = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExternalIdentifierMap.Contains(requestedVersion)) + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); - if(value is IEnumerable objectListExternalIdentifierMap) + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) { - foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(externalIdentifierMapItem); - } + writer.WriteStringValue(externalIdentifierMapItem); } - + writer.WriteEndArray(); - break; - case "goal": - var allowedVersionsForGoal = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("goal"u8); - if(!allowedVersionsForGoal.Contains(requestedVersion)) + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(goalItem); } - writer.WriteStartArray("goal"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); - if(value is IEnumerable objectListGoal) + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + writer.WriteOrderedItem(optionItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("possibleFiniteStateList"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleFiniteStateListItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(publicationItem); } - break; - case "iterationsetup": - var allowedVersionsForIterationSetup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); - if(!allowedVersionsForIterationSetup.Contains(requestedVersion)) + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relationshipItem); } - writer.WritePropertyName("iterationSetup"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requirementsSpecificationItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(ruleVerificationListItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sharedDiagramStyleItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(iteration.SourceIterationIid.Value); } else { writer.WriteNullValue(); } - break; - case "option": - var allowedVersionsForOption = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("stakeholder"u8); - if(!allowedVersionsForOption.Contains(requestedVersion)) + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderItem); } - writer.WriteStartArray("option"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); - if(value is IEnumerable objectListOption) + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(optionItem); - } + writer.WriteStringValue(stakeholderValueItem); } - + writer.WriteEndArray(); - break; - case "possiblefinitestatelist": - var allowedVersionsForPossibleFiniteStateList = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("stakeholderValueMap"u8); - if(!allowedVersionsForPossibleFiniteStateList.Contains(requestedVersion)) + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderValueMapItem); } - writer.WriteStartArray("possibleFiniteStateList"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("topElement"u8); - if(value is IEnumerable objectListPossibleFiniteStateList) + if(iteration.TopElement.HasValue) { - foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleFiniteStateListItem); - } + writer.WriteStringValue(iteration.TopElement.Value); } - - writer.WriteEndArray(); - break; - case "publication": - var allowedVersionsForPublication = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPublication.Contains(requestedVersion)) + else { - return; + writer.WriteNullValue(); } - writer.WriteStartArray("publication"u8); + writer.WriteStartArray("valueGroup"u8); - if(value is IEnumerable objectListPublication) + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) { - foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publicationItem); - } + writer.WriteStringValue(valueGroupItem); } - + writer.WriteEndArray(); + break; - case "relationship": - var allowedVersionsForRelationship = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - if(!allowedVersionsForRelationship.Contains(requestedVersion)) + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(actualFiniteStateListItem); } - writer.WriteStartArray("relationship"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); - if(value is IEnumerable objectListRelationship) + if(iteration.DefaultOption.HasValue) { - foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relationshipItem); - } + writer.WriteStringValue(iteration.DefaultOption.Value); } - - writer.WriteEndArray(); - break; - case "requirementsspecification": - var allowedVersionsForRequirementsSpecification = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRequirementsSpecification.Contains(requestedVersion)) + else { - return; + writer.WriteNullValue(); } - writer.WriteStartArray("requirementsSpecification"u8); + writer.WriteStartArray("diagramCanvas"u8); - if(value is IEnumerable objectListRequirementsSpecification) + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) { - foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteStringValue(diagramCanvasItem); } - + writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("domainFileStore"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainFileStoreItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "ruleverificationlist": - var allowedVersionsForRuleVerificationList = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("element"u8); - if(!allowedVersionsForRuleVerificationList.Contains(requestedVersion)) + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(elementItem); } - writer.WriteStartArray("ruleVerificationList"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListRuleVerificationList) + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleVerificationListItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "shareddiagramstyle": - var allowedVersionsForSharedDiagramStyle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForSharedDiagramStyle.Contains(requestedVersion)) + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("sharedDiagramStyle"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); - if(value is IEnumerable objectListSharedDiagramStyle) + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) { - foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sharedDiagramStyleItem); - } + writer.WriteStringValue(externalIdentifierMapItem); } - + writer.WriteEndArray(); - break; - case "sourceiterationiid": - var allowedVersionsForSourceIterationIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("goal"u8); - if(!allowedVersionsForSourceIterationIid.Contains(requestedVersion)) + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(goalItem); } - writer.WritePropertyName("sourceIterationIid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "stakeholder": - var allowedVersionsForStakeholder = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); - if(!allowedVersionsForStakeholder.Contains(requestedVersion)) + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(optionItem); } - writer.WriteStartArray("stakeholder"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); - if(value is IEnumerable objectListStakeholder) + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } + writer.WriteStringValue(possibleFiniteStateListItem); } - + writer.WriteEndArray(); - break; - case "stakeholdervalue": - var allowedVersionsForStakeholderValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("publication"u8); - if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(publicationItem); } - writer.WriteStartArray("stakeholderValue"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); - if(value is IEnumerable objectListStakeholderValue) + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) { - foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStringValue(relationshipItem); } - + writer.WriteEndArray(); - break; - case "stakeholdervaluemap": - var allowedVersionsForStakeholderValueMap = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("requirementsSpecification"u8); - if(!allowedVersionsForStakeholderValueMap.Contains(requestedVersion)) + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requirementsSpecificationItem); } - writer.WriteStartArray("stakeholderValueMap"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - if(value is IEnumerable objectListStakeholderValueMap) + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) { - foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueMapItem); - } + writer.WriteStringValue(ruleVerificationListItem); } - + writer.WriteEndArray(); - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("sharedDiagramStyle"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sharedDiagramStyleItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(iteration.SourceIterationIid.Value); } else { writer.WriteNullValue(); } - break; - case "topelement": - var allowedVersionsForTopElement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("stakeholder"u8); - if(!allowedVersionsForTopElement.Contains(requestedVersion)) + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderItem); } - writer.WritePropertyName("topElement"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(stakeholderValueItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(stakeholderValueMapItem); } - break; - case "valuegroup": - var allowedVersionsForValueGroup = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); - if(!allowedVersionsForValueGroup.Contains(requestedVersion)) + if(iteration.TopElement.HasValue) { - return; + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); } writer.WriteStartArray("valueGroup"u8); - if(value is IEnumerable objectListValueGroup) + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) { - foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStringValue(valueGroupItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Iteration iteration) - { - throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WriteStartObject(); + if(iteration.Actor.HasValue) + { + writer.WriteStringValue(iteration.Actor.Value); + } + else + { + writer.WriteNullValue(); + } - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.0.0"); writer.WriteStartArray("actualFiniteStateList"u8); foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -841,6 +666,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); writer.WritePropertyName("defaultOption"u8); @@ -854,6 +680,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) @@ -862,6 +697,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("element"u8); foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) @@ -870,6 +706,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) @@ -878,10 +733,22 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); writer.WritePropertyName("iterationSetup"u8); writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WriteStartArray("option"u8); foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) @@ -890,6 +757,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -898,6 +766,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) @@ -906,6 +775,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) @@ -914,6 +784,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) @@ -922,6 +793,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); writer.WriteStartArray("ruleVerificationList"u8); @@ -932,644 +804,660 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - writer.WritePropertyName("sourceIterationIid"u8); + + writer.WriteStartArray("sharedDiagramStyle"u8); - if(iteration.SourceIterationIid.HasValue) - { - writer.WriteStringValue(iteration.SourceIterationIid.Value); - } - else + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(sharedDiagramStyleItem); } - writer.WritePropertyName("topElement"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); - if(iteration.TopElement.HasValue) + if(iteration.SourceIterationIid.HasValue) { - writer.WriteStringValue(iteration.TopElement.Value); + writer.WriteStringValue(iteration.SourceIterationIid.Value); } else { writer.WriteNullValue(); } - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.1.0"); - writer.WriteStartArray("actualFiniteStateList"u8); + writer.WriteStartArray("stakeholder"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(actualFiniteStateListItem); + writer.WriteStringValue(stakeholderItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iteration.ClassKind.ToString()); - writer.WritePropertyName("defaultOption"u8); + + writer.WriteStartArray("stakeholderValue"u8); - if(iteration.DefaultOption.HasValue) - { - writer.WriteStringValue(iteration.DefaultOption.Value); - } - else + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(stakeholderValueItem); } - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(diagramCanvasItem); + writer.WriteStringValue(stakeholderValueMapItem); } writer.WriteEndArray(); - writer.WriteStartArray("domainFileStore"u8); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if(iteration.TopElement.HasValue) { - writer.WriteStringValue(domainFileStoreItem); + writer.WriteStringValue(iteration.TopElement.Value); } - - writer.WriteEndArray(); - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(elementItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("valueGroup"u8); - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue(valueGroupItem); } writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WriteStartArray("externalIdentifierMap"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(externalIdentifierMapItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("actor"u8); + + if(value != null) { - writer.WriteStringValue(goalItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iteration.Iid); - writer.WritePropertyName("iterationSetup"u8); - writer.WriteStringValue(iteration.IterationSetup); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(optionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + break; + case "actualfinitestatelist": + if(!AllowedVersionsPerProperty["actualFiniteStateList"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleFiniteStateListItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("publication"u8); + writer.WriteStartArray("actualFiniteStateList"u8); - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListActualFiniteStateList) { - writer.WriteStringValue(publicationItem); + foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { - writer.WriteStringValue(relationshipItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("classKind"u8); + + if(value != null) { - writer.WriteStringValue(requirementsSpecificationItem); + writer.WriteStringValue(((ClassKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(ruleVerificationListItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "defaultoption": + if(!AllowedVersionsPerProperty["defaultOption"].Contains(requestedVersion)) { - writer.WriteStringValue(sharedDiagramStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("sourceIterationIid"u8); - - if(iteration.SourceIterationIid.HasValue) + writer.WritePropertyName("defaultOption"u8); + + if(value != null) { - writer.WriteStringValue(iteration.SourceIterationIid.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + break; + case "diagramcanvas": + if(!AllowedVersionsPerProperty["diagramCanvas"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderValueItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValueMap"u8); + writer.WriteStartArray("diagramCanvas"u8); - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDiagramCanvas) { - writer.WriteStringValue(stakeholderValueMapItem); + foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("topElement"u8); - - if(iteration.TopElement.HasValue) - { - writer.WriteStringValue(iteration.TopElement.Value); - } - else + break; + case "domainfilestore": + if(!AllowedVersionsPerProperty["domainFileStore"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("domainFileStore"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDomainFileStore) { - writer.WriteStringValue(valueGroupItem); + foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } } - + writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.2.0"); - writer.WriteStartArray("actualFiniteStateList"u8); - - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + case "element": + if(!AllowedVersionsPerProperty["element"].Contains(requestedVersion)) { - writer.WriteStringValue(actualFiniteStateListItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iteration.ClassKind.ToString()); - writer.WritePropertyName("defaultOption"u8); + writer.WriteStartArray("element"u8); - if(iteration.DefaultOption.HasValue) + if(value is IEnumerable objectListElement) { - writer.WriteStringValue(iteration.DefaultOption.Value); + foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(diagramCanvasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("domainFileStore"u8); - - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(domainFileStoreItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("element"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(elementItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "externalidentifiermap": + if(!AllowedVersionsPerProperty["externalIdentifierMap"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("externalIdentifierMap"u8); - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExternalIdentifierMap) { - writer.WriteStringValue(excludedPersonItem); + foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + break; + case "goal": + if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) { - writer.WriteStringValue(externalIdentifierMapItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("goal"u8); - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGoal) { - writer.WriteStringValue(goalItem); + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iteration.Iid); - writer.WritePropertyName("iterationSetup"u8); - writer.WriteStringValue(iteration.IterationSetup); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteOrderedItem(optionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(possibleFiniteStateListItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(publicationItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + break; + case "iterationsetup": + if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) { - writer.WriteStringValue(relationshipItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iterationSetup"u8); + + if(value != null) { - writer.WriteStringValue(requirementsSpecificationItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(ruleVerificationListItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(sharedDiagramStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("sourceIterationIid"u8); - - if(iteration.SourceIterationIid.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(iteration.SourceIterationIid.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + break; + case "option": + if(!AllowedVersionsPerProperty["option"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValue"u8); + writer.WriteStartArray("option"u8); - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListOption) { - writer.WriteStringValue(stakeholderValueItem); + foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValueMap"u8); - - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + break; + case "possiblefinitestatelist": + if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderValueMapItem); + return; } + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + } + writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(iteration.ThingPreference); - writer.WritePropertyName("topElement"u8); + break; + case "publication": + if(!AllowedVersionsPerProperty["publication"].Contains(requestedVersion)) + { + return; + } - if(iteration.TopElement.HasValue) + writer.WriteStartArray("publication"u8); + + if(value is IEnumerable objectListPublication) { - writer.WriteStringValue(iteration.TopElement.Value); + foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } } - else + + writer.WriteEndArray(); + break; + case "relationship": + if(!AllowedVersionsPerProperty["relationship"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("relationship"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelationship) { - writer.WriteStringValue(valueGroupItem); + foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } } - + writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Iteration for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(iteration.Actor.HasValue) - { - writer.WriteStringValue(iteration.Actor.Value); - } - else + case "requirementsspecification": + if(!AllowedVersionsPerProperty["requirementsSpecification"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("actualFiniteStateList"u8); + writer.WriteStartArray("requirementsSpecification"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRequirementsSpecification) { - writer.WriteStringValue(actualFiniteStateListItem); + foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iteration.ClassKind.ToString()); - writer.WritePropertyName("defaultOption"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(iteration.DefaultOption.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(iteration.DefaultOption.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("diagramCanvas"u8); - - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + break; + case "ruleverificationlist": + if(!AllowedVersionsPerProperty["ruleVerificationList"].Contains(requestedVersion)) { - writer.WriteStringValue(diagramCanvasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("domainFileStore"u8); + writer.WriteStartArray("ruleVerificationList"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRuleVerificationList) { - writer.WriteStringValue(domainFileStoreItem); + foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + break; + case "shareddiagramstyle": + if(!AllowedVersionsPerProperty["sharedDiagramStyle"].Contains(requestedVersion)) { - writer.WriteStringValue(elementItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("sharedDiagramStyle"u8); - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSharedDiagramStyle) { - writer.WriteStringValue(excludedDomainItem); + foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceiterationiid": + if(!AllowedVersionsPerProperty["sourceIterationIid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("sourceIterationIid"u8); + + if(value != null) { - writer.WriteStringValue(externalIdentifierMapItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(goalItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iteration.Iid); - writer.WritePropertyName("iterationSetup"u8); - writer.WriteStringValue(iteration.IterationSetup); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "stakeholder": + if(!AllowedVersionsPerProperty["stakeholder"].Contains(requestedVersion)) { - writer.WriteOrderedItem(optionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("possibleFiniteStateList"u8); + writer.WriteStartArray("stakeholder"u8); - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListStakeholder) { - writer.WriteStringValue(possibleFiniteStateListItem); + foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) { - writer.WriteStringValue(publicationItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("relationship"u8); + writer.WriteStartArray("stakeholderValue"u8); - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListStakeholderValue) { - writer.WriteStringValue(relationshipItem); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + break; + case "stakeholdervaluemap": + if(!AllowedVersionsPerProperty["stakeholderValueMap"].Contains(requestedVersion)) { - writer.WriteStringValue(requirementsSpecificationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); + writer.WriteStartArray("stakeholderValueMap"u8); - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListStakeholderValueMap) { - writer.WriteStringValue(ruleVerificationListItem); + foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(sharedDiagramStyleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("sourceIterationIid"u8); - - if(iteration.SourceIterationIid.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(iteration.SourceIterationIid.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("stakeholderValueMap"u8); - - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + break; + case "topelement": + if(!AllowedVersionsPerProperty["topElement"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderValueMapItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(iteration.ThingPreference); writer.WritePropertyName("topElement"u8); - - if(iteration.TopElement.HasValue) + + if(value != null) { - writer.WriteStringValue(iteration.TopElement.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "valuegroup": + if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListValueGroup) { - writer.WriteStringValue(valueGroupItem); + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramCanvas", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "domainFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "element", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalIdentifierMap", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "option", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publication", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationship", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requirementsSpecification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerificationList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedDiagramStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholder", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueMap", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index 5f6ab1369..ade206847 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,60 +51,64 @@ namespace CDP4JsonSerializer public class IterationSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); - writer.WritePropertyName("classKind"u8); - - if(value != null) + if(iterationSetup.SourceIterationSetup.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } else { @@ -111,304 +116,232 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "description": - var allowedVersionsForDescription = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDescription.Contains(requestedVersion)) + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("description"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(iterationSetup.SourceIterationSetup.HasValue) { - return; + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + else { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteNullValue(); } - - writer.WriteEndArray(); + break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "frozenon": - var allowedVersionsForFrozenOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForFrozenOn.Contains(requestedVersion)) + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("frozenOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); - - if(value != null) + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); break; - case "isdeleted": - var allowedVersionsForIsDeleted = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeleted.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("isDeleted"u8); - - if(value != null) + if(iterationSetup.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(iterationSetup.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "iterationiid": - var allowedVersionsForIterationIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIterationIid.Contains(requestedVersion)) + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("iterationIid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "iterationnumber": - var allowedVersionsForIterationNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIterationNumber.Contains(requestedVersion)) + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("iterationNumber"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); writer.WritePropertyName("modifiedOn"u8); - - if(value != null) + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } else { writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } + writer.WriteEndObject(); + } - break; - case "sourceiterationsetup": - var allowedVersionsForSourceIterationSetup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForSourceIterationSetup.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("sourceIterationSetup"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -420,94 +353,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { writer.WriteNullValue(); } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the IterationSetup"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not IterationSetup iterationSetup) - { - throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iterationSetup.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(iterationSetup.Description); - writer.WritePropertyName("frozenOn"u8); - - if(iterationSetup.FrozenOn.HasValue) + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { - writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iterationSetup.Iid); - writer.WritePropertyName("isDeleted"u8); - writer.WriteBooleanValue(iterationSetup.IsDeleted); - writer.WritePropertyName("iterationIid"u8); - writer.WriteStringValue(iterationSetup.IterationIid); - writer.WritePropertyName("iterationNumber"u8); - writer.WriteNumberValue(iterationSetup.IterationNumber); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iterationSetup.RevisionNumber); - writer.WritePropertyName("sourceIterationSetup"u8); + break; + case "description": + if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.SourceIterationSetup.HasValue) + writer.WritePropertyName("description"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + writer.WriteStringValue((string)value); } else { @@ -515,58 +407,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iterationSetup.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(iterationSetup.Description); + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("frozenOn"u8); + break; + case "frozenon": + if(!AllowedVersionsPerProperty["frozenOn"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.FrozenOn.HasValue) + writer.WritePropertyName("frozenOn"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iterationSetup.Iid); - writer.WritePropertyName("isDeleted"u8); - writer.WriteBooleanValue(iterationSetup.IsDeleted); - writer.WritePropertyName("iterationIid"u8); - writer.WriteStringValue(iterationSetup.IterationIid); - writer.WritePropertyName("iterationNumber"u8); - writer.WriteNumberValue(iterationSetup.IterationNumber); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iterationSetup.RevisionNumber); - writer.WritePropertyName("sourceIterationSetup"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.SourceIterationSetup.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + writer.WriteStringValue((Guid)value); } else { @@ -574,145 +479,158 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iterationSetup.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(iterationSetup.Description); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + case "isdeleted": + if(!AllowedVersionsPerProperty["isDeleted"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeleted"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("frozenOn"u8); + break; + case "iterationiid": + if(!AllowedVersionsPerProperty["iterationIid"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.FrozenOn.HasValue) + writer.WritePropertyName("iterationIid"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iterationSetup.Iid); - writer.WritePropertyName("isDeleted"u8); - writer.WriteBooleanValue(iterationSetup.IsDeleted); - writer.WritePropertyName("iterationIid"u8); - writer.WriteStringValue(iterationSetup.IterationIid); - writer.WritePropertyName("iterationNumber"u8); - writer.WriteNumberValue(iterationSetup.IterationNumber); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iterationSetup.RevisionNumber); - writer.WritePropertyName("sourceIterationSetup"u8); + break; + case "iterationnumber": + if(!AllowedVersionsPerProperty["iterationNumber"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.SourceIterationSetup.HasValue) + writer.WritePropertyName("iterationNumber"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(iterationSetup.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing IterationSetup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.Actor.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(iterationSetup.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(iterationSetup.Description); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("frozenOn"u8); + break; + case "sourceiterationsetup": + if(!AllowedVersionsPerProperty["sourceIterationSetup"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.FrozenOn.HasValue) + writer.WritePropertyName("sourceIterationSetup"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(iterationSetup.Iid); - writer.WritePropertyName("isDeleted"u8); - writer.WriteBooleanValue(iterationSetup.IsDeleted); - writer.WritePropertyName("iterationIid"u8); - writer.WriteStringValue(iterationSetup.IterationIid); - writer.WritePropertyName("iterationNumber"u8); - writer.WriteNumberValue(iterationSetup.IterationNumber); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(iterationSetup.RevisionNumber); - writer.WritePropertyName("sourceIterationSetup"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(iterationSetup.SourceIterationSetup.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(iterationSetup.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the IterationSetup"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "frozenOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeleted", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 75ef50fd7..6a462edc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,317 +51,321 @@ namespace CDP4JsonSerializer public class LinearConversionUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not LinearConversionUnit linearConversionUnit) + { + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "conversionfactor": - var allowedVersionsForConversionFactor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForConversionFactor.Contains(requestedVersion)) + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("conversionFactor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(linearConversionUnit.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(linearConversionUnit.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForName.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -368,25 +373,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "referenceunit": - var allowedVersionsForReferenceUnit = new List + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForReferenceUnit.Contains(requestedVersion)) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("referenceUnit"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -394,25 +409,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "conversionfactor": + if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("conversionFactor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((string)value); } else { @@ -420,49 +427,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForShortName.Contains(requestedVersion)) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue((string)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -470,283 +517,159 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the LinearConversionUnit"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not LinearConversionUnit linearConversionUnit) - { - throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(linearConversionUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(linearConversionUnit.Name); - writer.WritePropertyName("referenceUnit"u8); - writer.WriteStringValue(linearConversionUnit.ReferenceUnit); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(linearConversionUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(linearConversionUnit.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(linearConversionUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(linearConversionUnit.Name); - writer.WritePropertyName("referenceUnit"u8); - writer.WriteStringValue(linearConversionUnit.ReferenceUnit); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(linearConversionUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(linearConversionUnit.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "referenceunit": + if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(linearConversionUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(linearConversionUnit.Name); - writer.WritePropertyName("referenceUnit"u8); - writer.WriteStringValue(linearConversionUnit.ReferenceUnit); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(linearConversionUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(linearConversionUnit.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(linearConversionUnit.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing LinearConversionUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(linearConversionUnit.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(linearConversionUnit.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(linearConversionUnit.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(linearConversionUnit.Name); - writer.WritePropertyName("referenceUnit"u8); - writer.WriteStringValue(linearConversionUnit.ReferenceUnit); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(linearConversionUnit.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(linearConversionUnit.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(linearConversionUnit.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the LinearConversionUnit"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index bb2eb50c7..b6919f1eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,141 @@ namespace CDP4JsonSerializer /// public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not LogEntryChangelogItem logEntryChangelogItem) + { + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.2.0"); + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logEntryChangelogItem.Actor.HasValue) + { + writer.WriteStringValue(logEntryChangelogItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +192,7 @@ public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerial /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +200,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,13 +218,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "affecteditemiid": - var allowedVersionsForAffectedItemIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) { return; } @@ -110,13 +236,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "affectedreferenceiid": - var allowedVersionsForAffectedReferenceIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAffectedReferenceIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["affectedReferenceIid"].Contains(requestedVersion)) { return; } @@ -134,13 +254,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "changedescription": - var allowedVersionsForChangeDescription = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForChangeDescription.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["changeDescription"].Contains(requestedVersion)) { return; } @@ -158,13 +272,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "changelogkind": - var allowedVersionsForChangelogKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForChangelogKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["changelogKind"].Contains(requestedVersion)) { return; } @@ -182,13 +290,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -206,14 +308,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -231,14 +326,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -256,13 +344,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -280,14 +362,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -305,13 +380,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -329,13 +398,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -358,133 +421,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not LogEntryChangelogItem logEntryChangelogItem) - { - throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.2.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing LogEntryChangelogItem for Version 1.2.0"); - writer.WritePropertyName("affectedItemIid"u8); - writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - writer.WriteStartArray("affectedReferenceIid"u8); - - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) - { - writer.WriteStringValue(affectedReferenceIidItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeDescription"u8); - writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); - writer.WritePropertyName("changelogKind"u8); - writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logEntryChangelogItem.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(logEntryChangelogItem.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing LogEntryChangelogItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(logEntryChangelogItem.Actor.HasValue) - { - writer.WriteStringValue(logEntryChangelogItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("affectedItemIid"u8); - writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - writer.WriteStartArray("affectedReferenceIid"u8); - - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) - { - writer.WriteStringValue(affectedReferenceIidItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("changeDescription"u8); - writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); - writer.WritePropertyName("changelogKind"u8); - writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logEntryChangelogItem.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(logEntryChangelogItem.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "affectedItemIid", new []{ "1.2.0", "1.3.0" }}, + { "affectedReferenceIid", new []{ "1.2.0", "1.3.0" }}, + { "changeDescription", new []{ "1.2.0", "1.3.0" }}, + { "changelogKind", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index efd6a6ffa..04e2d9987 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,370 +51,509 @@ namespace CDP4JsonSerializer public class LogarithmicScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListAlias) + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(mappingToReferenceScaleItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceQuantityValueItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(mappingToReferenceScaleItem); } - + writer.WriteEndArray(); - break; - case "exponent": - var allowedVersionsForExponent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - if(!allowedVersionsForExponent.Contains(requestedVersion)) + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceQuantityValueItem); } - writer.WritePropertyName("exponent"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "factor": - var allowedVersionsForFactor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForFactor.Contains(requestedVersion)) + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("factor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(mappingToReferenceScaleItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(referenceQuantityValueItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logarithmicScale.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(logarithmicScale.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "ismaximuminclusive": - var allowedVersionsForIsMaximumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "isminimuminclusive": - var allowedVersionsForIsMinimumInclusive = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(referenceQuantityValueItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "logarithmbase": - var allowedVersionsForLogarithmBase = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForLogarithmBase.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("logarithmBase"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue(((LogarithmBaseKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -421,47 +561,103 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "mappingtoreferencescale": - var allowedVersionsForMappingToReferenceScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("mappingToReferenceScale"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListMappingToReferenceScale) + if(value is IEnumerable objectListAlias) { - foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "maximumpermissiblevalue": - var allowedVersionsForMaximumPermissibleValue = new List + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); if(value != null) { @@ -473,21 +669,157 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "minimumpermissiblevalue": - var allowedVersionsForMinimumPermissibleValue = new List + case "factor": + if(!AllowedVersionsPerProperty["factor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("factor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logarithmbase": + if(!AllowedVersionsPerProperty["logarithmBase"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("logarithmBase"u8); + + if(value != null) + { + writer.WriteStringValue(((LogarithmBaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) { @@ -499,15 +831,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -525,15 +868,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -551,15 +886,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - var allowedVersionsForNegativeValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) { return; } @@ -577,15 +904,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - var allowedVersionsForNumberSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) { return; } @@ -603,15 +922,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - var allowedVersionsForPositiveValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) { return; } @@ -629,15 +940,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencequantitykind": - var allowedVersionsForReferenceQuantityKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferenceQuantityKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referenceQuantityKind"].Contains(requestedVersion)) { return; } @@ -655,15 +958,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencequantityvalue": - var allowedVersionsForReferenceQuantityValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferenceQuantityValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referenceQuantityValue"].Contains(requestedVersion)) { return; } @@ -681,15 +976,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -707,15 +994,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -733,13 +1012,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -757,15 +1030,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { return; } @@ -783,15 +1048,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - var allowedVersionsForValueDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { return; } @@ -814,453 +1071,40 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not LogarithmicScale logarithmicScale) - { - throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(logarithmicScale.Exponent); - writer.WritePropertyName("factor"u8); - writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logarithmicScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(logarithmicScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); - writer.WritePropertyName("logarithmBase"u8); - writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(logarithmicScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); - writer.WritePropertyName("referenceQuantityKind"u8); - writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logarithmicScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(logarithmicScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(logarithmicScale.Exponent); - writer.WritePropertyName("factor"u8); - writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logarithmicScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(logarithmicScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); - writer.WritePropertyName("logarithmBase"u8); - writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(logarithmicScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); - writer.WritePropertyName("referenceQuantityKind"u8); - writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logarithmicScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(logarithmicScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(logarithmicScale.Exponent); - writer.WritePropertyName("factor"u8); - writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logarithmicScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(logarithmicScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); - writer.WritePropertyName("logarithmBase"u8); - writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(logarithmicScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); - writer.WritePropertyName("referenceQuantityKind"u8); - writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logarithmicScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(logarithmicScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(logarithmicScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing LogarithmicScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(logarithmicScale.Actor.HasValue) - { - writer.WriteStringValue(logarithmicScale.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(logarithmicScale.Exponent); - writer.WritePropertyName("factor"u8); - writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(logarithmicScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(logarithmicScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); - writer.WritePropertyName("logarithmBase"u8); - writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(logarithmicScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); - writer.WritePropertyName("referenceQuantityKind"u8); - writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(logarithmicScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(logarithmicScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(logarithmicScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "factor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logarithmBase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index f5cc23eec..4514063da 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not MappingToReferenceScale mappingToReferenceScale) + { + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(mappingToReferenceScale.Actor.HasValue) + { + writer.WriteStringValue(mappingToReferenceScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSeri /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "dependentscalevalue": - var allowedVersionsForDependentScaleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDependentScaleValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["dependentScaleValue"].Contains(requestedVersion)) { return; } @@ -138,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencescalevalue": - var allowedVersionsForReferenceScaleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferenceScaleValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referenceScaleValue"].Contains(requestedVersion)) { return; } @@ -265,15 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not MappingToReferenceScale mappingToReferenceScale) - { - throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); - writer.WritePropertyName("dependentScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(mappingToReferenceScale.Iid); - writer.WritePropertyName("referenceScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); - writer.WritePropertyName("dependentScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(mappingToReferenceScale.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referenceScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); - writer.WritePropertyName("dependentScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(mappingToReferenceScale.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referenceScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(mappingToReferenceScale.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing MappingToReferenceScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(mappingToReferenceScale.Actor.HasValue) - { - writer.WriteStringValue(mappingToReferenceScale.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); - writer.WritePropertyName("dependentScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(mappingToReferenceScale.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referenceScaleValue"u8); - writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(mappingToReferenceScale.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dependentScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index 39cf32199..e2775bf9a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,288 +51,371 @@ namespace CDP4JsonSerializer public class ModelLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List + Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) { - "1.3.0", - }; + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(modelLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "affecteddomainiid": - var allowedVersionsForAffectedDomainIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForAffectedDomainIid.Contains(requestedVersion)) + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("affectedDomainIid"u8); - - if(value is IEnumerable objectListAffectedDomainIid) - { - foreach(var affectedDomainIidItem in objectListAffectedDomainIid) - { - writer.WriteStringValue((Guid)affectedDomainIidItem); - } - } - writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); break; - case "affecteditemiid": - var allowedVersionsForAffectedItemIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); - if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) { - return; + writer.WriteStringValue(affectedDomainIidItem); } - writer.WriteStartArray("affectedItemIid"u8); - - if(value is IEnumerable objectListAffectedItemIid) - { - foreach(var affectedItemIidItem in objectListAffectedItemIid) - { - writer.WriteStringValue((Guid)affectedItemIidItem); - } - } - writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(modelLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListCategory) + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(excludedDomainItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); break; - case "classkind": - var allowedVersionsForClassKind = new List + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(modelLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(logEntryChangelogItemItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelLogEntry.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(modelLogEntry.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("affectedDomainIid"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) { - return; + writer.WriteStringValue(affectedDomainIidItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(affectedItemIidItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -343,51 +427,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + case "affecteddomainiid": + if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); - - if(value != null) + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) { - writer.WriteStringValue((string)value); + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } } - else + + writer.WriteEndArray(); + break; + case "affecteditemiid": + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "level": - var allowedVersionsForLevel = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForLevel.Contains(requestedVersion)) + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("level"u8); + writer.WritePropertyName("author"u8); if(value != null) { - writer.WriteStringValue(((LogLevelKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -395,48 +481,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "logentrychangelogitem": - var allowedVersionsForLogEntryChangelogItem = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLogEntryChangelogItem.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("logEntryChangelogItem"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListLogEntryChangelogItem) + if(value is IEnumerable objectListCategory) { - foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(logEntryChangelogItemItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -444,25 +517,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((string)value); } else { @@ -470,23 +535,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -494,335 +553,196 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelLogEntry"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ModelLogEntry modelLogEntry) - { - throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.0.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedDomainIidItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(affectedItemIidItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(modelLogEntry.Author.HasValue) - { - writer.WriteStringValue(modelLogEntry.Author.Value); - } - else + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(modelLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(modelLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelLogEntry.RevisionNumber); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.1.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(modelLogEntry.Author.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(modelLogEntry.Author.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(modelLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("languageCode"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(modelLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelLogEntry.RevisionNumber); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.2.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + case "level": + if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(modelLogEntry.Author.HasValue) + writer.WritePropertyName("level"u8); + + if(value != null) { - writer.WriteStringValue(modelLogEntry.Author.Value); + writer.WriteStringValue(((LogLevelKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(modelLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "logentrychangelogitem": + if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListLogEntryChangelogItem) { - writer.WriteStringValue(excludedPersonItem); + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(modelLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(logEntryChangelogItemItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelLogEntry.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modelLogEntry.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ModelLogEntry for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(modelLogEntry.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(modelLogEntry.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(modelLogEntry.Author.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(modelLogEntry.Author.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(modelLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(modelLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(logEntryChangelogItemItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelLogEntry.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modelLogEntry.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelLogEntry"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index adee5fa3f..eb5656fcc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,718 +51,370 @@ namespace CDP4JsonSerializer public class ModelReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "basequantitykind": - var allowedVersionsForBaseQuantityKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForBaseQuantityKind.Contains(requestedVersion)) + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("baseQuantityKind"u8); - - if(value is IEnumerable objectListBaseQuantityKind) - { - foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(baseQuantityKindItem); - } - } - writer.WriteEndArray(); - break; - case "baseunit": - var allowedVersionsForBaseUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForBaseUnit.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("baseUnit"u8); - - if(value is IEnumerable objectListBaseUnit) - { - foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } - } - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("baseQuantityKind"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(baseQuantityKindItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "constant": - var allowedVersionsForConstant = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("baseUnit"u8); - if(!allowedVersionsForConstant.Contains(requestedVersion)) + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(baseUnitItem); } - writer.WriteStartArray("constant"u8); - - if(value is IEnumerable objectListConstant) - { - foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } - } - writer.WriteEndArray(); - break; - case "definedcategory": - var allowedVersionsForDefinedCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - if(!allowedVersionsForDefinedCategory.Contains(requestedVersion)) + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(constantItem); } - writer.WriteStartArray("definedCategory"u8); - - if(value is IEnumerable objectListDefinedCategory) - { - foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } - } - writer.WriteEndArray(); - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("definedCategory"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definedCategoryItem); } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("fileType"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(fileTypeItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "filetype": - var allowedVersionsForFileType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("glossary"u8); - if(!allowedVersionsForFileType.Contains(requestedVersion)) + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(glossaryItem); } - writer.WriteStartArray("fileType"u8); - - if(value is IEnumerable objectListFileType) - { - foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } - } - writer.WriteEndArray(); - break; - case "glossary": - var allowedVersionsForGlossary = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForGlossary.Contains(requestedVersion)) + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("glossary"u8); - - if(value is IEnumerable objectListGlossary) - { - foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterTypeItem); } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("referenceSource"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceSourceItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(ruleItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("scale"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(scaleItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(unitItem); } - writer.WriteStartArray("parameterType"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); - if(value is IEnumerable objectListParameterType) + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) { - foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStringValue(unitPrefixItem); } - + writer.WriteEndArray(); + break; - case "referencesource": - var allowedVersionsForReferenceSource = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForReferenceSource.Contains(requestedVersion)) + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("referenceSource"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); - if(value is IEnumerable objectListReferenceSource) + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteOrderedItem(baseQuantityKindItem); } - + writer.WriteEndArray(); - break; - case "requiredrdl": - var allowedVersionsForRequiredRdl = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("baseUnit"u8); - if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(baseUnitItem); } - writer.WritePropertyName("requiredRdl"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(constantItem); } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definedCategoryItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "rule": - var allowedVersionsForRule = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForRule.Contains(requestedVersion)) + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("rule"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListRule) + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("fileType"u8); - if(!allowedVersionsForScale.Contains(requestedVersion)) + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(fileTypeItem); } - writer.WriteStartArray("scale"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); - if(value is IEnumerable objectListScale) + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) { - foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + writer.WriteStringValue(glossaryItem); } - + writer.WriteEndArray(); - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(parameterTypeItem); } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceSourceItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); } else { writer.WriteNullValue(); } - break; - case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - if(!allowedVersionsForUnit.Contains(requestedVersion)) + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(ruleItem); } - writer.WriteStartArray("unit"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); - if(value is IEnumerable objectListUnit) + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) { - foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + writer.WriteStringValue(scaleItem); } - + writer.WriteEndArray(); - break; - case "unitprefix": - var allowedVersionsForUnitPrefix = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - if(!allowedVersionsForUnitPrefix.Contains(requestedVersion)) + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(unitItem); } + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - if(value is IEnumerable objectListUnitPrefix) + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) { - foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStringValue(unitPrefixItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) - { - throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -770,6 +423,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -778,6 +432,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -786,6 +441,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); writer.WriteStartArray("constant"u8); @@ -796,6 +452,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -804,6 +461,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -812,6 +470,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -820,6 +497,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -828,6 +506,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -836,8 +515,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); writer.WriteStartArray("parameterType"u8); @@ -848,6 +530,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -856,6 +539,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); if(modelReferenceDataLibrary.RequiredRdl.HasValue) @@ -877,6 +561,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -885,8 +570,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -895,6 +583,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -903,9 +592,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -914,6 +615,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -922,6 +624,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -930,6 +633,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); writer.WriteStartArray("constant"u8); @@ -940,6 +644,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -948,6 +653,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -956,6 +662,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -964,6 +671,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -972,6 +680,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -980,6 +689,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -988,6 +698,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -996,6 +707,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -1010,6 +722,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -1018,6 +731,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); if(modelReferenceDataLibrary.RequiredRdl.HasValue) @@ -1039,6 +753,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -1047,8 +762,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -1057,6 +775,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -1065,352 +784,534 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; } + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + writer.WriteEndArray(); + break; + case "basequantitykind": + if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListBaseQuantityKind) { - writer.WriteOrderedItem(baseQuantityKindItem); + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } } - + writer.WriteEndArray(); + break; + case "baseunit": + if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListBaseUnit) { - writer.WriteStringValue(baseUnitItem); + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + break; + case "constant": + if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) { - writer.WriteStringValue(constantItem); + return; } + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + writer.WriteEndArray(); + break; + case "definedcategory": + if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinedCategory) { - writer.WriteStringValue(definedCategoryItem); + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } } - + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListFileType) { - writer.WriteStringValue(fileTypeItem); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + break; + case "glossary": + if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) { - writer.WriteStringValue(glossaryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("glossary"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGlossary) { - writer.WriteStringValue(hyperLinkItem); + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterTypeItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referenceSource"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(referenceSourceItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("requiredRdl"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(modelReferenceDataLibrary.RequiredRdl.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(ruleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(scaleItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(unitItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(unitPrefixItem); + return; } - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(modelReferenceDataLibrary.Actor.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(modelReferenceDataLibrary.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("baseQuantityKind"u8); + writer.WriteStartArray("parameterType"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListParameterType) { - writer.WriteOrderedItem(baseQuantityKindItem); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + break; + case "referencesource": + if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) { - writer.WriteStringValue(baseUnitItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); + writer.WriteStartArray("referenceSource"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListReferenceSource) { - writer.WriteStringValue(constantItem); + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) { - writer.WriteStringValue(definedCategoryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(fileTypeItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + break; + case "rule": + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) { - writer.WriteStringValue(glossaryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("rule"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRule) { - writer.WriteStringValue(hyperLinkItem); + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterTypeItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referenceSource"u8); + writer.WriteStartArray("scale"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListScale) { - writer.WriteStringValue(referenceSourceItem); + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("requiredRdl"u8); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(modelReferenceDataLibrary.RequiredRdl.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(ruleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("scale"u8); + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { - writer.WriteStringValue(scaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUnit) { - writer.WriteStringValue(unitItem); + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } } - + writer.WriteEndArray(); + break; + case "unitprefix": + if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUnitPrefix) { - writer.WriteStringValue(unitPrefixItem); + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 35e0bb8a7..f2c660d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,152 @@ namespace CDP4JsonSerializer /// public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ModellingThingReference modellingThingReference) + { + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modellingThingReference.Actor.HasValue) + { + writer.WriteStringValue(modellingThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +203,7 @@ public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSeri /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +211,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +229,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +247,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +265,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -186,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -211,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedrevisionnumber": - var allowedVersionsForReferencedRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencedRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) { return; } @@ -236,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedthing": - var allowedVersionsForReferencedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) { return; } @@ -261,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -286,13 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -315,144 +396,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ModellingThingReference modellingThingReference) - { - throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modellingThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(modellingThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modellingThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(modellingThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modellingThingReference.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ModellingThingReference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(modellingThingReference.Actor.HasValue) - { - writer.WriteStringValue(modellingThingReference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modellingThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(modellingThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modellingThingReference.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modellingThingReference.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index d00ea6336..b16ada893 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,231 +51,500 @@ namespace CDP4JsonSerializer public class MultiRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - if(value is IEnumerable objectListAlias) + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(relatedCategoryItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(relatedCategoryItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedCategoryItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationshipRule.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(multiRelationshipRule.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -292,15 +562,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "maxrelated": - var allowedVersionsForMaxRelated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMaxRelated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["maxRelated"].Contains(requestedVersion)) { return; } @@ -318,15 +580,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minrelated": - var allowedVersionsForMinRelated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMinRelated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["minRelated"].Contains(requestedVersion)) { return; } @@ -344,14 +598,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -369,15 +616,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -395,15 +634,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedcategory": - var allowedVersionsForRelatedCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relatedCategory"].Contains(requestedVersion)) { return; } @@ -421,15 +652,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "relationshipcategory": - var allowedVersionsForRelationshipCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelationshipCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) { return; } @@ -447,15 +670,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -473,15 +688,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -499,13 +706,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -528,317 +729,29 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not MultiRelationshipRule multiRelationshipRule) - { - throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationshipRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); - writer.WritePropertyName("maxRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MaxRelated); - writer.WritePropertyName("minRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MinRelated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(multiRelationshipRule.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationshipRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); - writer.WritePropertyName("maxRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MaxRelated); - writer.WritePropertyName("minRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MinRelated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(multiRelationshipRule.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationshipRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); - writer.WritePropertyName("maxRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MaxRelated); - writer.WritePropertyName("minRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MinRelated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(multiRelationshipRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(multiRelationshipRule.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationshipRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(multiRelationshipRule.Actor.HasValue) - { - writer.WriteStringValue(multiRelationshipRule.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationshipRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); - writer.WritePropertyName("maxRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MaxRelated); - writer.WritePropertyName("minRelated"u8); - writer.WriteNumberValue(multiRelationshipRule.MinRelated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("relationshipCategory"u8); - writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(multiRelationshipRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(multiRelationshipRule.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index fb3357b34..a32f0b238 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,260 @@ namespace CDP4JsonSerializer /// public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not MultiRelationship multiRelationship) + { + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationship.Actor.HasValue) + { + writer.WriteStringValue(multiRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +311,7 @@ public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -112,15 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -138,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,13 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -263,15 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -289,14 +481,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - var allowedVersionsForParameterValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) { return; } @@ -314,15 +499,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { return; } @@ -340,15 +517,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -366,13 +535,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -395,241 +558,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not MultiRelationship multiRelationship) - { - throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.0.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationship.Iid); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationship.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationship.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationship.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationship.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(multiRelationship.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing MultiRelationship for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(multiRelationship.Actor.HasValue) - { - writer.WriteStringValue(multiRelationship.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(multiRelationship.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(multiRelationship.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(multiRelationship.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(multiRelationship.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index 6c4ddc067..f609812ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(naturalLanguage.Actor.HasValue) + { + writer.WriteStringValue(naturalLanguage.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -214,14 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -265,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "nativename": - var allowedVersionsForNativeName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNativeName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["nativeName"].Contains(requestedVersion)) { return; } @@ -291,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not NaturalLanguage naturalLanguage) - { - throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(naturalLanguage.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(naturalLanguage.LanguageCode); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(naturalLanguage.Name); - writer.WritePropertyName("nativeName"u8); - writer.WriteStringValue(naturalLanguage.NativeName); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(naturalLanguage.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(naturalLanguage.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(naturalLanguage.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(naturalLanguage.Name); - writer.WritePropertyName("nativeName"u8); - writer.WriteStringValue(naturalLanguage.NativeName); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(naturalLanguage.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(naturalLanguage.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(naturalLanguage.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(naturalLanguage.Name); - writer.WritePropertyName("nativeName"u8); - writer.WriteStringValue(naturalLanguage.NativeName); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(naturalLanguage.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(naturalLanguage.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing NaturalLanguage for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(naturalLanguage.Actor.HasValue) - { - writer.WriteStringValue(naturalLanguage.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(naturalLanguage.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(naturalLanguage.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(naturalLanguage.Name); - writer.WritePropertyName("nativeName"u8); - writer.WriteStringValue(naturalLanguage.NativeName); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(naturalLanguage.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(naturalLanguage.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nativeName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 25f580cc5..ec17d25b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,237 @@ namespace CDP4JsonSerializer /// public class NestedElementSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not NestedElement nestedElement) + { + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedElement.Actor.HasValue) + { + writer.WriteStringValue(nestedElement.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +288,7 @@ public class NestedElementSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "elementusage": - var allowedVersionsForElementUsage = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForElementUsage.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["elementUsage"].Contains(requestedVersion)) { return; } @@ -138,14 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +404,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isvolatile": - var allowedVersionsForIsVolatile = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsVolatile.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) { return; } @@ -240,14 +422,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +440,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "nestedparameter": - var allowedVersionsForNestedParameter = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNestedParameter.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["nestedParameter"].Contains(requestedVersion)) { return; } @@ -291,15 +458,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,15 +476,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rootelement": - var allowedVersionsForRootElement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRootElement.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["rootElement"].Contains(requestedVersion)) { return; } @@ -343,13 +494,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -372,221 +517,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not NestedElement nestedElement) - { - throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(elementUsageItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedElement.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedElement.IsVolatile); - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedElement.RevisionNumber); - writer.WritePropertyName("rootElement"u8); - writer.WriteStringValue(nestedElement.RootElement); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(elementUsageItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedElement.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedElement.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedElement.RevisionNumber); - writer.WritePropertyName("rootElement"u8); - writer.WriteStringValue(nestedElement.RootElement); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(elementUsageItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedElement.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedElement.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedElement.RevisionNumber); - writer.WritePropertyName("rootElement"u8); - writer.WriteStringValue(nestedElement.RootElement); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(nestedElement.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing NestedElement for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(nestedElement.Actor.HasValue) - { - writer.WriteStringValue(nestedElement.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(elementUsageItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedElement.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedElement.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedElement.RevisionNumber); - writer.WritePropertyName("rootElement"u8); - writer.WriteStringValue(nestedElement.RootElement); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(nestedElement.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementUsage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rootElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index a2599bba9..ead620444 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,233 @@ namespace CDP4JsonSerializer /// public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not NestedParameter nestedParameter) + { + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.0.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.1.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.2.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedParameter.Actor.HasValue) + { + writer.WriteStringValue(nestedParameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +284,7 @@ public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +292,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actualstate": - var allowedVersionsForActualState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForActualState.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) { return; } @@ -112,15 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actualvalue": - var allowedVersionsForActualValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForActualValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actualValue"].Contains(requestedVersion)) { return; } @@ -138,15 +346,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "associatedparameter": - var allowedVersionsForAssociatedParameter = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAssociatedParameter.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["associatedParameter"].Contains(requestedVersion)) { return; } @@ -164,15 +364,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -190,14 +382,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -215,14 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -240,15 +418,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "formula": - var allowedVersionsForFormula = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFormula.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) { return; } @@ -266,15 +436,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -292,15 +454,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isvolatile": - var allowedVersionsForIsVolatile = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsVolatile.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) { return; } @@ -318,14 +472,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -343,15 +490,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -369,15 +508,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -395,13 +526,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -424,225 +549,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not NestedParameter nestedParameter) - { - throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.0.0"); - writer.WritePropertyName("actualState"u8); - - if(nestedParameter.ActualState.HasValue) - { - writer.WriteStringValue(nestedParameter.ActualState.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("actualValue"u8); - writer.WriteStringValue(nestedParameter.ActualValue); - writer.WritePropertyName("associatedParameter"u8); - writer.WriteStringValue(nestedParameter.AssociatedParameter); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WritePropertyName("formula"u8); - writer.WriteStringValue(nestedParameter.Formula); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedParameter.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedParameter.IsVolatile); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(nestedParameter.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedParameter.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.1.0"); - writer.WritePropertyName("actualState"u8); - - if(nestedParameter.ActualState.HasValue) - { - writer.WriteStringValue(nestedParameter.ActualState.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("actualValue"u8); - writer.WriteStringValue(nestedParameter.ActualValue); - writer.WritePropertyName("associatedParameter"u8); - writer.WriteStringValue(nestedParameter.AssociatedParameter); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("formula"u8); - writer.WriteStringValue(nestedParameter.Formula); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedParameter.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedParameter.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(nestedParameter.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedParameter.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.2.0"); - writer.WritePropertyName("actualState"u8); - - if(nestedParameter.ActualState.HasValue) - { - writer.WriteStringValue(nestedParameter.ActualState.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("actualValue"u8); - writer.WriteStringValue(nestedParameter.ActualValue); - writer.WritePropertyName("associatedParameter"u8); - writer.WriteStringValue(nestedParameter.AssociatedParameter); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("formula"u8); - writer.WriteStringValue(nestedParameter.Formula); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedParameter.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedParameter.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(nestedParameter.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedParameter.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(nestedParameter.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing NestedParameter for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(nestedParameter.Actor.HasValue) - { - writer.WriteStringValue(nestedParameter.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("actualState"u8); - - if(nestedParameter.ActualState.HasValue) - { - writer.WriteStringValue(nestedParameter.ActualState.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("actualValue"u8); - writer.WriteStringValue(nestedParameter.ActualValue); - writer.WritePropertyName("associatedParameter"u8); - writer.WriteStringValue(nestedParameter.AssociatedParameter); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("formula"u8); - writer.WriteStringValue(nestedParameter.Formula); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(nestedParameter.Iid); - writer.WritePropertyName("isVolatile"u8); - writer.WriteBooleanValue(nestedParameter.IsVolatile); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(nestedParameter.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(nestedParameter.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(nestedParameter.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "associatedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 46c14ccad..31a6ead32 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,157 @@ namespace CDP4JsonSerializer /// public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not NotExpression notExpression) + { + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(notExpression.Actor.HasValue) + { + writer.WriteStringValue(notExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +208,7 @@ public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +216,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +234,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +252,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +270,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - var allowedVersionsForTerm = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTerm.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) { return; } @@ -265,13 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -294,149 +383,20 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not NotExpression notExpression) - { - throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(notExpression.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(notExpression.RevisionNumber); - writer.WritePropertyName("term"u8); - writer.WriteStringValue(notExpression.Term); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(notExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(notExpression.RevisionNumber); - writer.WritePropertyName("term"u8); - writer.WriteStringValue(notExpression.Term); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(notExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(notExpression.RevisionNumber); - writer.WritePropertyName("term"u8); - writer.WriteStringValue(notExpression.Term); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(notExpression.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing NotExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(notExpression.Actor.HasValue) - { - writer.WriteStringValue(notExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(notExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(notExpression.RevisionNumber); - writer.WritePropertyName("term"u8); - writer.WriteStringValue(notExpression.Term); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(notExpression.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 2dbb091a5..7090d29fd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,369 @@ namespace CDP4JsonSerializer public class OptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - if(value is IEnumerable objectListAlias) + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(nestedElementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - if(value is IEnumerable objectListDefinition) + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(nestedElementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(nestedElementItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(option.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(option.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "nestedelement": - var allowedVersionsForNestedElement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForNestedElement.Contains(requestedVersion)) + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); writer.WriteStartArray("nestedElement"u8); - if(value is IEnumerable objectListNestedElement) + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) { - foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedElementItem); - } + writer.WriteStringValue(nestedElementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,49 +421,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -444,323 +475,230 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Option"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Option option) - { - throw new ArgumentException("The thing shall be a Option", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(option.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(option.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(nestedElementItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(option.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(option.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(excludedDomainItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(option.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(nestedElementItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(option.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(option.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "nestedelement": + if(!AllowedVersionsPerProperty["nestedElement"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(option.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(option.Name); writer.WriteStartArray("nestedElement"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListNestedElement) { - writer.WriteStringValue(nestedElementItem); + foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(option.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(option.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(option.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Option for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(option.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(option.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(option.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(nestedElementItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(option.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(option.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(option.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Option"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index 923a18674..5cd8ddfb5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,185 @@ namespace CDP4JsonSerializer /// public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(orExpression.Actor.HasValue) + { + writer.WriteStringValue(orExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +236,7 @@ public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +298,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +316,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +334,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +352,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +370,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - var allowedVersionsForTerm = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTerm.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) { return; } @@ -265,13 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -294,173 +411,20 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not OrExpression orExpression) - { - throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(orExpression.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(orExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(orExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(orExpression.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing OrExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(orExpression.Actor.HasValue) - { - writer.WriteStringValue(orExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(orExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(orExpression.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 621dc57aa..33ee7da57 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,370 +51,449 @@ namespace CDP4JsonSerializer public class OrdinalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not OrdinalScale ordinalScale) + { + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListAlias) + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(mappingToReferenceScaleItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ordinalScale.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(ordinalScale.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "ismaximuminclusive": - var allowedVersionsForIsMaximumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "isminimuminclusive": - var allowedVersionsForIsMinimumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "mappingtoreferencescale": - var allowedVersionsForMappingToReferenceScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListMappingToReferenceScale) + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStringValue(mappingToReferenceScaleItem); } - + writer.WriteEndArray(); - break; - case "maximumpermissiblevalue": - var allowedVersionsForMaximumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - break; - case "minimumpermissiblevalue": - var allowedVersionsForMinimumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -421,50 +501,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,51 +537,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "negativevalueconnotation": - var allowedVersionsForNegativeValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("negativeValueConnotation"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - case "numberset": - var allowedVersionsForNumberSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("numberSet"u8); - + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + if(value != null) { - writer.WriteStringValue(((NumberSetKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -524,21 +627,85 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "positivevalueconnotation": - var allowedVersionsForPositiveValueConnotation = new List + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } - if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("positiveValueConnotation"u8); + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) { @@ -550,16 +717,116 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -577,15 +844,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -603,13 +862,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -627,15 +880,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { return; } @@ -653,15 +898,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "useshortnamevalues": - var allowedVersionsForUseShortNameValues = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUseShortNameValues.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["useShortNameValues"].Contains(requestedVersion)) { return; } @@ -679,15 +916,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - var allowedVersionsForValueDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { return; } @@ -710,397 +939,36 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not OrdinalScale ordinalScale) - { - throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ordinalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ordinalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ordinalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ordinalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ordinalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ordinalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ordinalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ordinalScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ordinalScale.Unit); - writer.WritePropertyName("useShortNameValues"u8); - writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ordinalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ordinalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ordinalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ordinalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ordinalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ordinalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ordinalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ordinalScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ordinalScale.Unit); - writer.WritePropertyName("useShortNameValues"u8); - writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ordinalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ordinalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ordinalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ordinalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ordinalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ordinalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ordinalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ordinalScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ordinalScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ordinalScale.Unit); - writer.WritePropertyName("useShortNameValues"u8); - writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing OrdinalScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(ordinalScale.Actor.HasValue) - { - writer.WriteStringValue(ordinalScale.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ordinalScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ordinalScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ordinalScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ordinalScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ordinalScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ordinalScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ordinalScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ordinalScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ordinalScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ordinalScale.Unit); - writer.WritePropertyName("useShortNameValues"u8); - writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "useShortNameValues", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 9a6f7b740..5c96221c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class OrganizationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organization.Actor.HasValue) + { + writer.WriteStringValue(organization.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class OrganizationSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -214,14 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -265,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -317,13 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Organization organization) - { - throw new ArgumentException("The thing shall be a Organization", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organization.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(organization.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(organization.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organization.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(organization.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organization.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(organization.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(organization.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organization.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(organization.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organization.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(organization.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(organization.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organization.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(organization.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(organization.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Organization for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(organization.Actor.HasValue) - { - writer.WriteStringValue(organization.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organization.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(organization.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(organization.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organization.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(organization.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(organization.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index a5664db18..cddea0cef 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,115 @@ namespace CDP4JsonSerializer /// public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not OrganizationalParticipant organizationalParticipant) + { + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organizationalParticipant.Actor.HasValue) + { + writer.WriteStringValue(organizationalParticipant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +166,7 @@ public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSe /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +174,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,13 +192,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -110,14 +210,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -135,14 +228,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -160,13 +246,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -184,14 +264,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -209,13 +282,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organization": - var allowedVersionsForOrganization = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOrganization.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) { return; } @@ -233,13 +300,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -257,13 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -286,109 +341,20 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not OrganizationalParticipant organizationalParticipant) - { - throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.2.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing OrganizationalParticipant for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organizationalParticipant.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("organization"u8); - writer.WriteStringValue(organizationalParticipant.Organization); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organizationalParticipant.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(organizationalParticipant.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing OrganizationalParticipant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(organizationalParticipant.Actor.HasValue) - { - writer.WriteStringValue(organizationalParticipant.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(organizationalParticipant.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("organization"u8); - writer.WriteStringValue(organizationalParticipant.Organization); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(organizationalParticipant.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(organizationalParticipant.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index ceb911321..a85d891e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,597 +51,195 @@ namespace CDP4JsonSerializer public class OwnedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not OwnedStyle ownedStyle) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); + return; + } - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "fillcolor": - var allowedVersionsForFillColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFillColor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("fillColor"u8); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "fillopacity": - var allowedVersionsForFillOpacity = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForFillOpacity.Contains(requestedVersion)) + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("fillOpacity"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((float)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "fontbold": - var allowedVersionsForFontBold = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontBold.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fillColor"u8); - writer.WritePropertyName("fontBold"u8); - - if(value != null) + if(ownedStyle.FillColor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(ownedStyle.FillColor.Value); } else { writer.WriteNullValue(); } - break; - case "fontcolor": - var allowedVersionsForFontColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontColor.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fillOpacity"u8); - writer.WritePropertyName("fontColor"u8); - - if(value != null) + if(ownedStyle.FillOpacity.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); } else { writer.WriteNullValue(); } - break; - case "fontitalic": - var allowedVersionsForFontItalic = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontItalic.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontBold"u8); - writer.WritePropertyName("fontItalic"u8); - - if(value != null) + if(ownedStyle.FontBold.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteBooleanValue(ownedStyle.FontBold.Value); } else { writer.WriteNullValue(); } - break; - case "fontname": - var allowedVersionsForFontName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontName.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontColor"u8); - writer.WritePropertyName("fontName"u8); - - if(value != null) + if(ownedStyle.FontColor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(ownedStyle.FontColor.Value); } else { writer.WriteNullValue(); } - break; - case "fontsize": - var allowedVersionsForFontSize = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontSize.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontItalic"u8); - writer.WritePropertyName("fontSize"u8); - - if(value != null) + if(ownedStyle.FontItalic.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); } else { writer.WriteNullValue(); } - break; - case "fontstrokethrough": - var allowedVersionsForFontStrokeThrough = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontStrokeThrough.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); - writer.WritePropertyName("fontStrokeThrough"u8); - - if(value != null) + if(ownedStyle.FontSize.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteNumberValue(ownedStyle.FontSize.Value); } else { writer.WriteNullValue(); } - break; - case "fontunderline": - var allowedVersionsForFontUnderline = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontUnderline.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontStrokeThrough"u8); - writer.WritePropertyName("fontUnderline"u8); - - if(value != null) + if(ownedStyle.FontStrokeThrough.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); } else { writer.WriteNullValue(); } - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontUnderline"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(ownedStyle.FontUnderline.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(ownedStyle.Name); writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "strokecolor": - var allowedVersionsForStrokeColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeColor.Contains(requestedVersion)) - { - return; - } - + writer.WriteNumberValue(ownedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "strokeopacity": - var allowedVersionsForStrokeOpacity = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeOpacity.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeOpacity"u8); - - if(value != null) + if(ownedStyle.StrokeColor.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteStringValue(ownedStyle.StrokeColor.Value); } else { writer.WriteNullValue(); } - break; - case "strokewidth": - var allowedVersionsForStrokeWidth = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeWidth.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("strokeOpacity"u8); - writer.WritePropertyName("strokeWidth"u8); - - if(value != null) + if(ownedStyle.StrokeOpacity.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); } else { writer.WriteNullValue(); } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("strokeWidth"u8); - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + if(ownedStyle.StrokeWidth.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); } else { writer.WriteNullValue(); } - break; - case "usedcolor": - var allowedVersionsForUsedColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUsedColor.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("usedColor"u8); - if(value is IEnumerable objectListUsedColor) + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) { - foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStringValue(usedColorItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not OwnedStyle ownedStyle) - { - throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -651,6 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -659,6 +259,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); if(ownedStyle.FillColor.HasValue) @@ -790,6 +391,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -798,9 +401,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ownedStyle.Actor.HasValue) + { + writer.WriteStringValue(ownedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -811,6 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -819,6 +435,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); if(ownedStyle.FillColor.HasValue) @@ -902,244 +519,516 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if(ownedStyle.FontUnderline.HasValue) { - writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ownedStyle.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ownedStyle.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ownedStyle.RevisionNumber); - writer.WritePropertyName("strokeColor"u8); + break; + case "fillopacity": + if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeColor.HasValue) + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) { - writer.WriteStringValue(ownedStyle.StrokeColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeOpacity"u8); + break; + case "fontbold": + if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeOpacity.HasValue) + writer.WritePropertyName("fontBold"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeWidth"u8); + break; + case "fontcolor": + if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeWidth.HasValue) + writer.WritePropertyName("fontColor"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ownedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + break; + case "fontitalic": + if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) { - writer.WriteStringValue(usedColorItem); + return; } - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing OwnedStyle for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(ownedStyle.Actor.HasValue) + writer.WritePropertyName("fontItalic"u8); + + if(value != null) { - writer.WriteStringValue(ownedStyle.Actor.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "fontname": + if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("fontName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("fillColor"u8); + break; + case "fontsize": + if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FillColor.HasValue) + writer.WritePropertyName("fontSize"u8); + + if(value != null) { - writer.WriteStringValue(ownedStyle.FillColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fillOpacity"u8); + break; + case "fontstrokethrough": + if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FillOpacity.HasValue) + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontBold"u8); + break; + case "fontunderline": + if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontBold.HasValue) + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) { - writer.WriteBooleanValue(ownedStyle.FontBold.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontColor"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontColor.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(ownedStyle.FontColor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontItalic"u8); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontItalic.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontName"u8); - writer.WriteStringValue(ownedStyle.FontName); - writer.WritePropertyName("fontSize"u8); + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontSize.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.FontSize.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontStrokeThrough"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontStrokeThrough.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontUnderline"u8); + break; + case "strokecolor": + if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.FontUnderline.HasValue) + writer.WritePropertyName("strokeColor"u8); + + if(value != null) { - writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ownedStyle.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ownedStyle.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ownedStyle.RevisionNumber); - writer.WritePropertyName("strokeColor"u8); + break; + case "strokeopacity": + if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeColor.HasValue) + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) { - writer.WriteStringValue(ownedStyle.StrokeColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeOpacity"u8); + break; + case "strokewidth": + if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeOpacity.HasValue) + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeWidth"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(ownedStyle.StrokeWidth.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ownedStyle.ThingPreference); + break; + case "usedcolor": + if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUsedColor) { - writer.WriteStringValue(usedColorItem); + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index cef6bb6db..d2820f39d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,218 @@ namespace CDP4JsonSerializer /// public class PageSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Page page) + { + throw new ArgumentException("The thing shall be a Page", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(page.Actor.HasValue) + { + writer.WriteStringValue(page.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +269,7 @@ public class PageSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +277,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +295,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -111,14 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +331,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -161,14 +349,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -186,14 +367,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -211,14 +385,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -236,14 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -261,14 +421,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -286,14 +439,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "note": - var allowedVersionsForNote = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNote.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) { return; } @@ -311,14 +457,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -336,14 +475,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,14 +493,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +511,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,204 +534,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Page page) - { - throw new ArgumentException("The thing shall be a Page", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(page.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(page.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(noteItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(page.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(page.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(page.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(page.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(page.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(noteItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(page.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(page.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(page.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(page.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Page for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(page.Actor.HasValue) - { - writer.WriteStringValue(page.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(page.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(page.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(noteItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(page.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(page.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(page.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(page.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index d2bb26180..81f5146b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,201 @@ namespace CDP4JsonSerializer /// public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterGroup.Actor.HasValue) + { + writer.WriteStringValue(parameterGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +252,7 @@ public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containinggroup": - var allowedVersionsForContainingGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContainingGroup.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["containingGroup"].Contains(requestedVersion)) { return; } @@ -138,14 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -265,15 +404,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +422,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -320,193 +445,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterGroup parameterGroup) - { - throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterGroup.ClassKind.ToString()); - writer.WritePropertyName("containingGroup"u8); - - if(parameterGroup.ContainingGroup.HasValue) - { - writer.WriteStringValue(parameterGroup.ContainingGroup.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterGroup.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterGroup.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterGroup.ClassKind.ToString()); - writer.WritePropertyName("containingGroup"u8); - - if(parameterGroup.ContainingGroup.HasValue) - { - writer.WriteStringValue(parameterGroup.ContainingGroup.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterGroup.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterGroup.ClassKind.ToString()); - writer.WritePropertyName("containingGroup"u8); - - if(parameterGroup.ContainingGroup.HasValue) - { - writer.WriteStringValue(parameterGroup.ContainingGroup.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterGroup.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterGroup.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterGroup.Actor.HasValue) - { - writer.WriteStringValue(parameterGroup.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterGroup.ClassKind.ToString()); - writer.WritePropertyName("containingGroup"u8); - - if(parameterGroup.ContainingGroup.HasValue) - { - writer.WriteStringValue(parameterGroup.ContainingGroup.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterGroup.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterGroup.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 7746b5d07..c3be67cda 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,237 @@ namespace CDP4JsonSerializer /// public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterOverride parameterOverride) + { + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverride.Actor.HasValue) + { + writer.WriteStringValue(parameterOverride.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +288,7 @@ public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +404,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -239,15 +422,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parameter": - var allowedVersionsForParameter = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameter.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) { return; } @@ -265,15 +440,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametersubscription": - var allowedVersionsForParameterSubscription = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterSubscription.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) { return; } @@ -291,15 +458,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +476,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -341,15 +494,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueset": - var allowedVersionsForValueSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueSet.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) { return; } @@ -372,221 +517,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterOverride parameterOverride) - { - throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverride.Iid); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterOverride.Owner); - writer.WritePropertyName("parameter"u8); - writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverride.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterOverride.Owner); - writer.WritePropertyName("parameter"u8); - writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverride.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterOverride.Owner); - writer.WritePropertyName("parameter"u8); - writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterOverride.ThingPreference); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverride for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterOverride.Actor.HasValue) - { - writer.WriteStringValue(parameterOverride.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverride.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterOverride.Owner); - writer.WritePropertyName("parameter"u8); - writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterOverride.ThingPreference); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 2cfd1c470..1c3b80807 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,185 @@ namespace CDP4JsonSerializer /// public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) + { + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverrideValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterOverrideValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +236,7 @@ public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSe /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "computed": - var allowedVersionsForComputed = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForComputed.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) { return; } @@ -128,14 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -153,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -178,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "formula": - var allowedVersionsForFormula = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFormula.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) { return; } @@ -194,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -220,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "manual": - var allowedVersionsForManual = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForManual.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) { return; } @@ -236,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -261,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalueset": - var allowedVersionsForParameterValueSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValueSet.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterValueSet"].Contains(requestedVersion)) { return; } @@ -287,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "published": - var allowedVersionsForPublished = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPublished.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) { return; } @@ -303,15 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); break; case "reference": - var allowedVersionsForReference = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) { return; } @@ -319,15 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -345,13 +428,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -369,15 +446,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueswitch": - var allowedVersionsForValueSwitch = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) { return; } @@ -400,177 +469,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) - { - throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); - writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverrideValueSet.Iid); - writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); - writer.WritePropertyName("parameterValueSet"u8); - writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); - writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); - writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); - writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverrideValueSet.Iid); - writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterValueSet"u8); - writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); - writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); - writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); - writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverrideValueSet.Iid); - writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterValueSet"u8); - writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); - writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); - writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterOverrideValueSet for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterOverrideValueSet.Actor.HasValue) - { - writer.WriteStringValue(parameterOverrideValueSet.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); - writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterOverrideValueSet.Iid); - writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterValueSet"u8); - writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); - writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); - writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index e9929f62a..edb35c055 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,540 +51,236 @@ namespace CDP4JsonSerializer public class ParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not Parameter parameter) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); + } - break; - case "allowdifferentownerofoverride": - var allowedVersionsForAllowDifferentOwnerOfOverride = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAllowDifferentOwnerOfOverride.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.0.0"); writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); - - if(value != null) + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(parameter.Group.Value); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterSubscriptionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "expectsoverride": - var allowedVersionsForExpectsOverride = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExpectsOverride.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); - writer.WritePropertyName("expectsOverride"u8); - - if(value != null) + if(parameter.RequestedBy.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(parameter.RequestedBy.Value); } else { writer.WriteNullValue(); } - break; - case "group": - var allowedVersionsForGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForGroup.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); - writer.WritePropertyName("group"u8); - - if(value != null) + if(parameter.Scale.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(parameter.Scale.Value); } else { writer.WriteNullValue(); } - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("stateDependence"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(parameter.StateDependence.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(parameter.StateDependence.Value); } else { writer.WriteNullValue(); } - break; - case "isoptiondependent": - var allowedVersionsForIsOptionDependent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("valueSet"u8); - if(!allowedVersionsForIsOptionDependent.Contains(requestedVersion)) + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueSetItem); } - writer.WritePropertyName("isOptionDependent"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.1.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("owner"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(parameter.Group.Value); } else { writer.WriteNullValue(); } - break; - case "parametersubscription": - var allowedVersionsForParameterSubscription = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterSubscription.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); writer.WriteStartArray("parameterSubscription"u8); - if(value is IEnumerable objectListParameterSubscription) - { - foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } - } - - writer.WriteEndArray(); - break; - case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterSubscriptionItem); } - writer.WritePropertyName("parameterType"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "requestedby": - var allowedVersionsForRequestedBy = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRequestedBy.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) + if(parameter.RequestedBy.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(parameter.RequestedBy.Value); } else { writer.WriteNullValue(); } - break; - case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); writer.WritePropertyName("scale"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "statedependence": - var allowedVersionsForStateDependence = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStateDependence.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("stateDependence"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + if(parameter.Scale.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(parameter.Scale.Value); } else { writer.WriteNullValue(); } - break; - case "valueset": - var allowedVersionsForValueSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("stateDependence"u8); - if(!allowedVersionsForValueSet.Contains(requestedVersion)) + if(parameter.StateDependence.HasValue) { - return; + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); } writer.WriteStartArray("valueSet"u8); - if(value is IEnumerable objectListValueSet) + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) { - foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStringValue(valueSetItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Parameter parameter) - { - throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.0.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.2.0"); writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); @@ -601,6 +298,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.Iid); writer.WritePropertyName("isOptionDependent"u8); writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); writer.WriteStartArray("parameterSubscription"u8); @@ -611,6 +310,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); @@ -648,6 +348,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -656,9 +358,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameter.Actor.HasValue) + { + writer.WriteStringValue(parameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); @@ -671,6 +385,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -679,6 +394,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); @@ -708,6 +424,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); @@ -721,254 +438,435 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameter.RevisionNumber); - writer.WritePropertyName("scale"u8); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "allowdifferentownerofoverride": + if(!AllowedVersionsPerProperty["allowDifferentOwnerOfOverride"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expectsoverride": + if(!AllowedVersionsPerProperty["expectsOverride"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("expectsOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } - if(parameter.Scale.HasValue) + writer.WritePropertyName("group"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Scale.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("stateDependence"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(parameter.StateDependence.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(parameter.StateDependence.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.2.0"); - writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); - writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + case "isoptiondependent": + if(!AllowedVersionsPerProperty["isOptionDependent"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("expectsOverride"u8); - writer.WriteBooleanValue(parameter.ExpectsOverride); - writer.WritePropertyName("group"u8); - - if(parameter.Group.HasValue) + writer.WritePropertyName("isOptionDependent"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Group.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameter.Iid); - writer.WritePropertyName("isOptionDependent"u8); - writer.WriteBooleanValue(parameter.IsOptionDependent); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterSubscriptionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameter.ParameterType); - writer.WritePropertyName("requestedBy"u8); - - if(parameter.RequestedBy.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(parameter.RequestedBy.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameter.RevisionNumber); - writer.WritePropertyName("scale"u8); + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } - if(parameter.Scale.HasValue) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Scale.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("stateDependence"u8); - - if(parameter.StateDependence.HasValue) - { - writer.WriteStringValue(parameter.StateDependence.Value); - } - else + break; + case "parametersubscription": + if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameter.ThingPreference); - writer.WriteStartArray("valueSet"u8); + writer.WriteStartArray("parameterSubscription"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterSubscription) { - writer.WriteStringValue(valueSetItem); + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } } - + writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Parameter for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } - if(parameter.Actor.HasValue) + writer.WritePropertyName("parameterType"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); - writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "requestedby": + if(!AllowedVersionsPerProperty["requestedBy"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("requestedBy"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("expectsOverride"u8); - writer.WriteBooleanValue(parameter.ExpectsOverride); - writer.WritePropertyName("group"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(parameter.Group.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Group.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameter.Iid); - writer.WritePropertyName("isOptionDependent"u8); - writer.WriteBooleanValue(parameter.IsOptionDependent); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterSubscriptionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameter.ParameterType); - writer.WritePropertyName("requestedBy"u8); - - if(parameter.RequestedBy.HasValue) + writer.WritePropertyName("scale"u8); + + if(value != null) { - writer.WriteStringValue(parameter.RequestedBy.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameter.RevisionNumber); - writer.WritePropertyName("scale"u8); + break; + case "statedependence": + if(!AllowedVersionsPerProperty["stateDependence"].Contains(requestedVersion)) + { + return; + } - if(parameter.Scale.HasValue) + writer.WritePropertyName("stateDependence"u8); + + if(value != null) { - writer.WriteStringValue(parameter.Scale.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("stateDependence"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(parameter.StateDependence.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(parameter.StateDependence.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameter.ThingPreference); + break; + case "valueset": + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListValueSet) { - writer.WriteStringValue(valueSetItem); + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "allowDifferentOwnerOfOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expectsOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isOptionDependent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requestedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stateDependence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 31ec83387..6832b54a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,193 @@ namespace CDP4JsonSerializer /// public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscription.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscription.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +244,7 @@ public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerial /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +252,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +270,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -239,15 +378,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -265,13 +396,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -289,15 +414,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueset": - var allowedVersionsForValueSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueSet.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) { return; } @@ -320,181 +437,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterSubscription parameterSubscription) - { - throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscription.Iid); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterSubscription.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscription.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterSubscription.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscription.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterSubscription.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterSubscription.ThingPreference); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscription for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterSubscription.Actor.HasValue) - { - writer.WriteStringValue(parameterSubscription.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscription.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(parameterSubscription.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterSubscription.ThingPreference); - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 3234ca5c1..41371a9c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,169 @@ namespace CDP4JsonSerializer /// public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) + { + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscriptionValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscriptionValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +220,7 @@ public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThi /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +228,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +246,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +264,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +282,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +300,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,15 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "manual": - var allowedVersionsForManual = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForManual.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) { return; } @@ -204,14 +326,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -229,15 +344,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -255,15 +362,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "subscribedvalueset": - var allowedVersionsForSubscribedValueSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSubscribedValueSet.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["subscribedValueSet"].Contains(requestedVersion)) { return; } @@ -281,13 +380,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -305,15 +398,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueswitch": - var allowedVersionsForValueSwitch = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) { return; } @@ -336,161 +421,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) - { - throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.Iid); - writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); - writer.WritePropertyName("subscribedValueSet"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.Iid); - writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); - writer.WritePropertyName("subscribedValueSet"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.Iid); - writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); - writer.WritePropertyName("subscribedValueSet"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterSubscriptionValueSet.Actor.HasValue) - { - writer.WriteStringValue(parameterSubscriptionValueSet.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.Iid); - writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); - writer.WritePropertyName("subscribedValueSet"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); - writer.WritePropertyName("valueSwitch"u8); - writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "subscribedValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 173e8bc3a..2c5253535 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,209 @@ namespace CDP4JsonSerializer /// public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParameterTypeComponent parameterTypeComponent) + { + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterTypeComponent.Actor.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +260,7 @@ public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSeria /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -239,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -265,15 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -291,15 +430,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -317,13 +448,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,201 +471,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParameterTypeComponent parameterTypeComponent) - { - throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterTypeComponent.Iid); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameterTypeComponent.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(parameterTypeComponent.Scale.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterTypeComponent.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterTypeComponent.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameterTypeComponent.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(parameterTypeComponent.Scale.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterTypeComponent.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterTypeComponent.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameterTypeComponent.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(parameterTypeComponent.Scale.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterTypeComponent.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterTypeComponent.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterTypeComponent for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterTypeComponent.Actor.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterTypeComponent.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(parameterTypeComponent.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(parameterTypeComponent.Scale.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterTypeComponent.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterTypeComponent.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 6ffcd74d7..56326cec5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,382 +50,6 @@ namespace CDP4JsonSerializer /// public class ParameterValueSetSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "actualoption": - var allowedVersionsForActualOption = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForActualOption.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actualOption"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "actualstate": - var allowedVersionsForActualState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForActualState.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actualState"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "computed": - var allowedVersionsForComputed = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForComputed.Contains(requestedVersion)) - { - return; - } - - writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "formula": - var allowedVersionsForFormula = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFormula.Contains(requestedVersion)) - { - return; - } - - writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "manual": - var allowedVersionsForManual = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForManual.Contains(requestedVersion)) - { - return; - } - - writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "published": - var allowedVersionsForPublished = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPublished.Contains(requestedVersion)) - { - return; - } - - writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); - break; - case "reference": - var allowedVersionsForReference = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReference.Contains(requestedVersion)) - { - return; - } - - writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "valueswitch": - var allowedVersionsForValueSwitch = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueSwitch.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("valueSwitch"u8); - - if(value != null) - { - writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterValueSet"); - } - } - /// /// Serializes a into an /// @@ -451,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.0.0"); writer.WritePropertyName("actualOption"u8); if(parameterValueSet.ActualOption.HasValue) @@ -489,7 +114,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.1.0"); writer.WritePropertyName("actualOption"u8); if(parameterValueSet.ActualOption.HasValue) @@ -523,6 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -531,6 +157,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterValueSet.Iid); @@ -545,7 +172,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.2.0"); writer.WritePropertyName("actualOption"u8); if(parameterValueSet.ActualOption.HasValue) @@ -579,6 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -587,6 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterValueSet.Iid); @@ -603,7 +232,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterValueSet for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(parameterValueSet.Actor.HasValue) @@ -648,6 +277,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -656,6 +286,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterValueSet.Iid); @@ -677,6 +308,286 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualoption": + if(!AllowedVersionsPerProperty["actualOption"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterValueSet"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index b300a61d0..a55f0d555 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,317 +51,349 @@ namespace CDP4JsonSerializer public class ParameterizedCategoryRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) + { + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - if(value is IEnumerable objectListAlias) + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(parameterTypeItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("category"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - if(value is IEnumerable objectListDefinition) + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(parameterTypeItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterTypeItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterizedCategoryRule.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(parameterizedCategoryRule.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(parameterTypeItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForName.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -368,51 +401,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("parameterType"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListParameterType) + if(value is IEnumerable objectListAlias) { - foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterTypeItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("category"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -420,25 +437,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterizedCategoryRule"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) - { - throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("category"u8); - writer.WriteStringValue(parameterizedCategoryRule.Category); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(definitionItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterizedCategoryRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(parameterTypeItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterizedCategoryRule.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("category"u8); - writer.WriteStringValue(parameterizedCategoryRule.Category); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterizedCategoryRule.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(parameterTypeItem); + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterizedCategoryRule.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("category"u8); - writer.WriteStringValue(parameterizedCategoryRule.Category); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterizedCategoryRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterizedCategoryRule.Name); writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterType) { - writer.WriteStringValue(parameterTypeItem); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterizedCategoryRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParameterizedCategoryRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(parameterizedCategoryRule.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(parameterizedCategoryRule.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("category"u8); - writer.WriteStringValue(parameterizedCategoryRule.Category); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(parameterizedCategoryRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(parameterTypeItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(parameterizedCategoryRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterizedCategoryRule"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 767379e48..225ac2c7e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,276 +50,6 @@ namespace CDP4JsonSerializer /// public class ParametricConstraintSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "expression": - var allowedVersionsForExpression = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExpression.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("expression"u8); - - if(value is IEnumerable objectListExpression) - { - foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(expressionItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "topexpression": - var allowedVersionsForTopExpression = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTopExpression.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("topExpression"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ParametricConstraint"); - } - } - /// /// Serializes a into an /// @@ -345,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); writer.WriteStartArray("expression"u8); @@ -356,6 +87,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); writer.WritePropertyName("revisionNumber"u8); @@ -373,7 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -384,6 +116,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -392,6 +125,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -400,6 +134,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -419,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -430,6 +165,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -438,6 +174,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -446,6 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -467,7 +205,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParametricConstraint for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(parametricConstraint.Actor.HasValue) @@ -489,6 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +236,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -505,6 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -531,6 +272,222 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expression": + if(!AllowedVersionsPerProperty["expression"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("expression"u8); + + if(value is IEnumerable objectListExpression) + { + foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topexpression": + if(!AllowedVersionsPerProperty["topExpression"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("topExpression"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParametricConstraint"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topExpression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index d3241fb99..1f5e997d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(participantPermission.Actor.HasValue) + { + writer.WriteStringValue(participantPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerial /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,15 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "accessright": - var allowedVersionsForAccessRight = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAccessRight.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) { return; } @@ -89,12 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -112,15 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -138,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -240,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "objectclass": - var allowedVersionsForObjectClass = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForObjectClass.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) { return; } @@ -291,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ParticipantPermission participantPermission) - { - throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.0.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(participantPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantPermission.IsDeprecated); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(participantPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantPermission.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.1.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(participantPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(participantPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantPermission.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.2.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(participantPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(participantPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantPermission.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participantPermission.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantPermission for Version 1.3.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(participantPermission.AccessRight.ToString()); - writer.WritePropertyName("actor"u8); - - if(participantPermission.Actor.HasValue) - { - writer.WriteStringValue(participantPermission.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(participantPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantPermission.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participantPermission.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 8d97e9a73..6e9fdced3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,291 +51,341 @@ namespace CDP4JsonSerializer public class ParticipantRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ParticipantRole participantRole) + { + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - if(value is IEnumerable objectListAlias) + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(participantPermissionItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(participantPermissionItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(participantPermissionItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participantRole.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(participantRole.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(participantPermissionItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForName.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -342,51 +393,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "participantpermission": - var allowedVersionsForParticipantPermission = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParticipantPermission.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("participantPermission"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListParticipantPermission) + if(value is IEnumerable objectListAlias) { - foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(participantPermissionItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -394,349 +429,248 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue((string)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantRole"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ParticipantRole participantRole) - { - throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(aliasItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantRole.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(participantPermissionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(participantRole.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantRole.IsDeprecated); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(participantPermissionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(participantRole.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "participantpermission": + if(!AllowedVersionsPerProperty["participantPermission"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantRole.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(participantRole.Name); writer.WriteStartArray("participantPermission"u8); - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParticipantPermission) { - writer.WriteStringValue(participantPermissionItem); + foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(participantRole.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participantRole.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ParticipantRole for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(participantRole.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(participantRole.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participantRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(participantRole.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(participantPermissionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participantRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(participantRole.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participantRole.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantRole"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index e178a731d..1f162cfc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,217 @@ namespace CDP4JsonSerializer /// public class ParticipantSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Participant participant) + { + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participant.Actor.HasValue) + { + writer.WriteStringValue(participant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +268,7 @@ public class ParticipantSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +276,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +294,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +312,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "domain": - var allowedVersionsForDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) { return; } @@ -138,14 +330,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +366,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - var allowedVersionsForIsActive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsActive.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) { return; } @@ -240,14 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "person": - var allowedVersionsForPerson = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) { return; } @@ -291,15 +438,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,15 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "role": - var allowedVersionsForRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRole.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) { return; } @@ -343,15 +474,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "selecteddomain": - var allowedVersionsForSelectedDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSelectedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["selectedDomain"].Contains(requestedVersion)) { return; } @@ -369,13 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -398,205 +515,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Participant participant) - { - throw new ArgumentException("The thing shall be a Participant", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participant.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(participant.IsActive); - writer.WritePropertyName("person"u8); - writer.WriteStringValue(participant.Person); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participant.RevisionNumber); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(participant.Role); - writer.WritePropertyName("selectedDomain"u8); - writer.WriteStringValue(participant.SelectedDomain); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participant.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(participant.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("person"u8); - writer.WriteStringValue(participant.Person); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participant.RevisionNumber); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(participant.Role); - writer.WritePropertyName("selectedDomain"u8); - writer.WriteStringValue(participant.SelectedDomain); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participant.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(participant.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("person"u8); - writer.WriteStringValue(participant.Person); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participant.RevisionNumber); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(participant.Role); - writer.WritePropertyName("selectedDomain"u8); - writer.WriteStringValue(participant.SelectedDomain); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participant.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Participant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(participant.Actor.HasValue) - { - writer.WriteStringValue(participant.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(participant.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(participant.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("person"u8); - writer.WriteStringValue(participant.Person); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(participant.RevisionNumber); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(participant.Role); - writer.WritePropertyName("selectedDomain"u8); - writer.WriteStringValue(participant.SelectedDomain); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(participant.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "selectedDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index d253e3ace..a9ffb3fa6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,173 @@ namespace CDP4JsonSerializer /// public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(personPermission.Actor.HasValue) + { + writer.WriteStringValue(personPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +224,7 @@ public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,15 +232,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "accessright": - var allowedVersionsForAccessRight = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAccessRight.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) { return; } @@ -89,12 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -112,15 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -138,14 +286,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +304,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +322,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +340,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -240,14 +358,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +376,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "objectclass": - var allowedVersionsForObjectClass = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForObjectClass.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) { return; } @@ -291,15 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +412,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,165 +435,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not PersonPermission personPermission) - { - throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.0.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(personPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personPermission.IsDeprecated); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(personPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personPermission.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.1.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(personPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(personPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personPermission.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.2.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(personPermission.AccessRight.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(personPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personPermission.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(personPermission.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing PersonPermission for Version 1.3.0"); - writer.WritePropertyName("accessRight"u8); - writer.WriteStringValue(personPermission.AccessRight.ToString()); - writer.WritePropertyName("actor"u8); - - if(personPermission.Actor.HasValue) - { - writer.WriteStringValue(personPermission.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personPermission.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personPermission.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("objectClass"u8); - writer.WriteStringValue(personPermission.ObjectClass.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personPermission.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(personPermission.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 6fecd76eb..780e0d508 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,291 +51,341 @@ namespace CDP4JsonSerializer public class PersonRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not PersonRole personRole) + { + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - if(value is IEnumerable objectListAlias) + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(personPermissionItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(personPermissionItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(personPermissionItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(personRole.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(personRole.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(personPermissionItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForName.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -342,51 +393,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "personpermission": - var allowedVersionsForPersonPermission = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPersonPermission.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("personPermission"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListPersonPermission) + if(value is IEnumerable objectListAlias) { - foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(personPermissionItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -394,349 +429,248 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue((string)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonRole"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not PersonRole personRole) - { - throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(aliasItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personRole.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(personPermissionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(personRole.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personRole.IsDeprecated); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(personPermissionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(personRole.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "personpermission": + if(!AllowedVersionsPerProperty["personPermission"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personRole.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(personRole.Name); writer.WriteStartArray("personPermission"u8); - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPersonPermission) { - writer.WriteStringValue(personPermissionItem); + foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(personRole.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(personRole.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing PersonRole for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(personRole.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(personRole.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(personRole.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(personRole.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(personPermissionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(personRole.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(personRole.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(personRole.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonRole"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index 632571c77..5c6802131 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,640 +51,262 @@ namespace CDP4JsonSerializer public class PersonSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not Person person) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.0.0"); writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "defaultdomain": - var allowedVersionsForDefaultDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefaultDomain.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); - - if(value != null) + + if(person.DefaultDomain.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(person.DefaultDomain.Value); } else { writer.WriteNullValue(); } - break; - case "defaultemailaddress": - var allowedVersionsForDefaultEmailAddress = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefaultEmailAddress.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultEmailAddress"u8); - - if(value != null) + + if(person.DefaultEmailAddress.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(person.DefaultEmailAddress.Value); } else { writer.WriteNullValue(); } - break; - case "defaulttelephonenumber": - var allowedVersionsForDefaultTelephoneNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefaultTelephoneNumber.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultTelephoneNumber"u8); - - if(value != null) + + if(person.DefaultTelephoneNumber.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } else { writer.WriteNullValue(); } - break; - case "emailaddress": - var allowedVersionsForEmailAddress = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForEmailAddress.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("emailAddress"u8); - if(value is IEnumerable objectListEmailAddress) - { - foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(emailAddressItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(emailAddressItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "givenname": - var allowedVersionsForGivenName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForGivenName.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("givenName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(person.GivenName); writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isactive": - var allowedVersionsForIsActive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsActive.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(person.Iid); writer.WritePropertyName("isActive"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) - { - return; - } - + writer.WriteBooleanValue(person.IsActive); writer.WritePropertyName("isDeprecated"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("organization"u8); - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) + if(person.Organization.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(person.Organization.Value); } else { writer.WriteNullValue(); } - break; - case "organization": - var allowedVersionsForOrganization = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOrganization.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); - writer.WritePropertyName("organization"u8); - - if(value != null) + if(person.Role.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(person.Role.Value); } else { writer.WriteNullValue(); } - break; - case "organizationalunit": - var allowedVersionsForOrganizationalUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - if(!allowedVersionsForOrganizationalUnit.Contains(requestedVersion)) + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(telephoneNumberItem); } - writer.WritePropertyName("organizationalUnit"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "password": - var allowedVersionsForPassword = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("userPreference"u8); - if(!allowedVersionsForPassword.Contains(requestedVersion)) + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(userPreferenceItem); } - writer.WritePropertyName("password"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) + if(person.DefaultDomain.HasValue) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(person.DefaultDomain.Value); } else { writer.WriteNullValue(); } - break; - case "role": - var allowedVersionsForRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRole.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("defaultEmailAddress"u8); - writer.WritePropertyName("role"u8); - - if(value != null) + if(person.DefaultEmailAddress.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(person.DefaultEmailAddress.Value); } else { writer.WriteNullValue(); } - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("defaultTelephoneNumber"u8); - writer.WritePropertyName("shortName"u8); - - if(value != null) + if(person.DefaultTelephoneNumber.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } else { writer.WriteNullValue(); } - break; - case "surname": - var allowedVersionsForSurname = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("emailAddress"u8); - if(!allowedVersionsForSurname.Contains(requestedVersion)) + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(emailAddressItem); } - writer.WritePropertyName("surname"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "telephonenumber": - var allowedVersionsForTelephoneNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForTelephoneNumber.Contains(requestedVersion)) + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("telephoneNumber"u8); - - if(value is IEnumerable objectListTelephoneNumber) - { - foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(telephoneNumberItem); - } - } - writer.WriteEndArray(); - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(person.Organization.Value); } else { writer.WriteNullValue(); } - break; - case "userpreference": - var allowedVersionsForUserPreference = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUserPreference.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("userPreference"u8); + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); - if(value is IEnumerable objectListUserPreference) + if(person.Role.HasValue) { - foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(userPreferenceItem); - } - } - - writer.WriteEndArray(); - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Person person) - { - throw new ArgumentException("The thing shall be a Person", nameof(thing)); - } + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); - return; - } + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - writer.WriteStartObject(); + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.0.0"); + writer.WriteEndArray(); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); @@ -727,6 +350,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); writer.WritePropertyName("iid"u8); @@ -735,6 +377,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(person.IsActive); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("organization"u8); if(person.Organization.HasValue) @@ -775,6 +419,9 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -783,9 +430,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(person.Actor.HasValue) + { + writer.WriteStringValue(person.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); @@ -829,6 +488,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -837,6 +497,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -845,6 +506,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); writer.WritePropertyName("iid"u8); @@ -895,6 +557,9 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -903,268 +568,477 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.2.0"); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(person.ClassKind.ToString()); - writer.WritePropertyName("defaultDomain"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - if(person.DefaultDomain.HasValue) + break; + case "defaultdomain": + if(!AllowedVersionsPerProperty["defaultDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(person.DefaultDomain.Value); + return; + } + + writer.WritePropertyName("defaultDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "defaultemailaddress": + if(!AllowedVersionsPerProperty["defaultEmailAddress"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("defaultEmailAddress"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - if(person.DefaultEmailAddress.HasValue) + break; + case "defaulttelephonenumber": + if(!AllowedVersionsPerProperty["defaultTelephoneNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "emailaddress": + if(!AllowedVersionsPerProperty["emailAddress"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("emailAddress"u8); + + if(value is IEnumerable objectListEmailAddress) + { + foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "givenname": + if(!AllowedVersionsPerProperty["givenName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("givenName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(person.DefaultEmailAddress.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("defaultTelephoneNumber"u8); + break; + case "isactive": + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) + { + return; + } - if(person.DefaultTelephoneNumber.HasValue) + writer.WritePropertyName("isActive"u8); + + if(value != null) { - writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(emailAddressItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("givenName"u8); - writer.WriteStringValue(person.GivenName); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(person.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(person.IsActive); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(person.IsDeprecated); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("organization"u8); - - if(person.Organization.HasValue) + + if(value != null) { - writer.WriteStringValue(person.Organization.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("organizationalUnit"u8); - writer.WriteStringValue(person.OrganizationalUnit); - writer.WritePropertyName("password"u8); - writer.WriteStringValue(person.Password); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(person.RevisionNumber); - writer.WritePropertyName("role"u8); + break; + case "organization": + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) + { + return; + } - if(person.Role.HasValue) + writer.WritePropertyName("organization"u8); + + if(value != null) { - writer.WriteStringValue(person.Role.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(person.ShortName); - writer.WritePropertyName("surname"u8); - writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + break; + case "organizationalunit": + if(!AllowedVersionsPerProperty["organizationalUnit"].Contains(requestedVersion)) { - writer.WriteStringValue(telephoneNumberItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(person.ThingPreference); - writer.WriteStartArray("userPreference"u8); - - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("organizationalUnit"u8); + + if(value != null) { - writer.WriteStringValue(userPreferenceItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Person for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "password": + if(!AllowedVersionsPerProperty["password"].Contains(requestedVersion)) + { + return; + } - if(person.Actor.HasValue) + writer.WritePropertyName("password"u8); + + if(value != null) { - writer.WriteStringValue(person.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(person.ClassKind.ToString()); - writer.WritePropertyName("defaultDomain"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(person.DefaultDomain.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(person.DefaultDomain.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("defaultEmailAddress"u8); + break; + case "role": + if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) + { + return; + } - if(person.DefaultEmailAddress.HasValue) + writer.WritePropertyName("role"u8); + + if(value != null) { - writer.WriteStringValue(person.DefaultEmailAddress.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("defaultTelephoneNumber"u8); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(person.DefaultTelephoneNumber.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + break; + case "surname": + if(!AllowedVersionsPerProperty["surname"].Contains(requestedVersion)) { - writer.WriteStringValue(emailAddressItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("surname"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "telephonenumber": + if(!AllowedVersionsPerProperty["telephoneNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("givenName"u8); - writer.WriteStringValue(person.GivenName); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(person.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(person.IsActive); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(person.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("organization"u8); + writer.WriteStartArray("telephoneNumber"u8); - if(person.Organization.HasValue) + if(value is IEnumerable objectListTelephoneNumber) { - writer.WriteStringValue(person.Organization.Value); + foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } } - else + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WritePropertyName("organizationalUnit"u8); - writer.WriteStringValue(person.OrganizationalUnit); - writer.WritePropertyName("password"u8); - writer.WriteStringValue(person.Password); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(person.RevisionNumber); - writer.WritePropertyName("role"u8); - - if(person.Role.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(person.Role.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(person.ShortName); - writer.WritePropertyName("surname"u8); - writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + break; + case "userpreference": + if(!AllowedVersionsPerProperty["userPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(telephoneNumberItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(person.ThingPreference); writer.WriteStartArray("userPreference"u8); - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUserPreference) { - writer.WriteStringValue(userPreferenceItem); + foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultEmailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultTelephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "emailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "givenName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "password", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "surname", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "telephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "userPreference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 971c3903f..4140edf0e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,158 @@ namespace CDP4JsonSerializer /// public class PointSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(point.Actor.HasValue) + { + writer.WriteStringValue(point.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +209,7 @@ public class PointSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +217,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +235,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +253,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +271,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +289,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -186,14 +307,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -211,14 +325,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -236,14 +343,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -261,13 +361,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -285,14 +379,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "x": - var allowedVersionsForX = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForX.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) { return; } @@ -310,14 +397,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "y": - var allowedVersionsForY = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForY.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) { return; } @@ -340,150 +420,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Point point) - { - throw new ArgumentException("The thing shall be a Point", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(point.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(point.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(point.RevisionNumber); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(point.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(point.Y); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(point.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(point.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(point.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(point.ThingPreference); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(point.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(point.Y); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Point for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(point.Actor.HasValue) - { - writer.WriteStringValue(point.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(point.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(point.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(point.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(point.ThingPreference); - writer.WritePropertyName("x"u8); - writer.WriteNumberValue(point.X); - writer.WritePropertyName("y"u8); - writer.WriteNumberValue(point.Y); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 0d1cd3b88..4c5bea084 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,521 +51,252 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) { - "1.3.0", - }; + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } else { writer.WriteNullValue(); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - if(value is IEnumerable objectListCategory) + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteOrderedItem(possibleStateItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "defaultstate": - var allowedVersionsForDefaultState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForDefaultState.Contains(requestedVersion)) + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("defaultState"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } else { writer.WriteNullValue(); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteOrderedItem(possibleStateItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("owner"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "possiblestate": - var allowedVersionsForPossibleState = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPossibleState.Contains(requestedVersion)) - { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("possibleState"u8); - - if(value is IEnumerable objectListPossibleState) - { - foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(possibleStateItem); - } - } - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteStateList"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not PossibleFiniteStateList possibleFiniteStateList) - { - throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); - writer.WritePropertyName("defaultState"u8); - - if(possibleFiniteStateList.DefaultState.HasValue) - { - writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -573,8 +305,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); @@ -587,13 +322,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(possibleFiniteStateList.Actor.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -602,6 +351,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("category"u8); foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) @@ -610,6 +360,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); writer.WritePropertyName("defaultState"u8); @@ -631,6 +382,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -639,6 +391,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -647,6 +400,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -655,6 +409,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -671,200 +426,369 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.2.0"); - writer.WriteStartArray("alias"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); - writer.WritePropertyName("defaultState"u8); - - if(possibleFiniteStateList.DefaultState.HasValue) + writer.WritePropertyName("actor"u8); + + if(value != null) { - writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("alias"u8); - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(excludedDomainItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("category"u8); - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListCategory) { - writer.WriteStringValue(hyperLinkItem); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(possibleFiniteStateList.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(possibleFiniteStateList.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(possibleFiniteStateList.Owner); - writer.WriteStartArray("possibleState"u8); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + writer.WritePropertyName("classKind"u8); + + if(value != null) { - writer.WriteOrderedItem(possibleStateItem); + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(possibleFiniteStateList.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(possibleFiniteStateList.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteStateList for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "defaultstate": + if(!AllowedVersionsPerProperty["defaultState"].Contains(requestedVersion)) + { + return; + } - if(possibleFiniteStateList.Actor.HasValue) + writer.WritePropertyName("defaultState"u8); + + if(value != null) { - writer.WriteStringValue(possibleFiniteStateList.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(aliasItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; } + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); - writer.WritePropertyName("defaultState"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(possibleFiniteStateList.DefaultState.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "possiblestate": + if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(possibleFiniteStateList.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(possibleFiniteStateList.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(possibleFiniteStateList.Owner); writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListPossibleState) { - writer.WriteOrderedItem(possibleStateItem); + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } } - + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(possibleFiniteStateList.ShortName); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteStateList"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index 8829ee1bb..0d47f7b5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,354 +50,6 @@ namespace CDP4JsonSerializer /// public class PossibleFiniteStateSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteState"); - } - } - /// /// Serializes a into an /// @@ -423,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.0.0"); + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -432,6 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -442,6 +96,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -450,6 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); writer.WritePropertyName("name"u8); @@ -460,7 +116,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteState.ShortName); break; case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -469,6 +125,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -479,6 +136,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -487,6 +145,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -495,6 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -503,6 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -515,7 +176,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteState.ShortName); break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -524,6 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -534,6 +196,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -542,6 +205,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -550,6 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -558,6 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -572,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteState.ThingPreference); break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing PossibleFiniteState for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(possibleFiniteState.Actor.HasValue) @@ -592,6 +258,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -602,6 +269,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -610,6 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -618,6 +287,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -626,6 +296,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -645,6 +316,279 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteState"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index f6ed496f1..42104de74 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,424 +51,112 @@ namespace CDP4JsonSerializer public class PrefixedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not PrefixedUnit prefixedUnit) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); writer.WritePropertyName("isDeprecated"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "prefix": - var allowedVersionsForPrefix = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrefix.Contains(requestedVersion)) - { - return; - } - + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); writer.WritePropertyName("prefix"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "referenceunit": - var allowedVersionsForReferenceUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferenceUnit.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(prefixedUnit.Prefix); writer.WritePropertyName("referenceUnit"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the PrefixedUnit"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not PrefixedUnit prefixedUnit) - { - throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(excludedDomainItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -476,10 +165,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("prefix"u8); writer.WriteStringValue(prefixedUnit.Prefix); writer.WritePropertyName("referenceUnit"u8); @@ -487,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(prefixedUnit.RevisionNumber); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +189,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -507,6 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -515,6 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -523,6 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -531,6 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -543,9 +240,22 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(prefixedUnit.ReferenceUnit); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(prefixedUnit.Actor.HasValue) + { + writer.WriteStringValue(prefixedUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -554,6 +264,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -564,6 +275,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -572,6 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -580,6 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -588,6 +302,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -603,82 +318,304 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(prefixedUnit.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing PrefixedUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(prefixedUnit.Actor.HasValue) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(prefixedUnit.Actor.Value); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("alias"u8); - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(aliasItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(prefixedUnit.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "prefix": + if(!AllowedVersionsPerProperty["prefix"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("prefix"u8); - writer.WriteStringValue(prefixedUnit.Prefix); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("referenceUnit"u8); - writer.WriteStringValue(prefixedUnit.ReferenceUnit); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(prefixedUnit.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(prefixedUnit.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the PrefixedUnit"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "prefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index 69e006cea..d1beffcf6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,229 @@ namespace CDP4JsonSerializer /// public class PublicationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(publication.Actor.HasValue) + { + writer.WriteStringValue(publication.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +280,7 @@ public class PublicationSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -138,15 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "domain": - var allowedVersionsForDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) { return; } @@ -164,14 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -189,14 +378,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -214,15 +396,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -240,14 +414,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +432,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "publishedparameter": - var allowedVersionsForPublishedParameter = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPublishedParameter.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["publishedParameter"].Contains(requestedVersion)) { return; } @@ -291,15 +450,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -317,13 +468,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -346,213 +491,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Publication publication) - { - throw new ArgumentException("The thing shall be a Publication", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(publication.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(publication.Iid); - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(publication.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(publication.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(publication.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(publication.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(publication.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(publication.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(publication.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(publication.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Publication for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(publication.Actor.HasValue) - { - writer.WriteStringValue(publication.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(publication.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(publication.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(publication.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(publication.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 0519f1a24..966d9d818 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not QuantityKindFactor quantityKindFactor) + { + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(quantityKindFactor.Actor.HasValue) + { + writer.WriteStringValue(quantityKindFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerialize /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "exponent": - var allowedVersionsForExponent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExponent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) { return; } @@ -188,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "quantitykind": - var allowedVersionsForQuantityKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForQuantityKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["quantityKind"].Contains(requestedVersion)) { return; } @@ -265,15 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,13 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not QuantityKindFactor quantityKindFactor) - { - throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(quantityKindFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(quantityKindFactor.Iid); - writer.WritePropertyName("quantityKind"u8); - writer.WriteStringValue(quantityKindFactor.QuantityKind); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(quantityKindFactor.RevisionNumber); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(quantityKindFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(quantityKindFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("quantityKind"u8); - writer.WriteStringValue(quantityKindFactor.QuantityKind); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(quantityKindFactor.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(quantityKindFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(quantityKindFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("quantityKind"u8); - writer.WriteStringValue(quantityKindFactor.QuantityKind); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(quantityKindFactor.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(quantityKindFactor.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing QuantityKindFactor for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(quantityKindFactor.Actor.HasValue) - { - writer.WriteStringValue(quantityKindFactor.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(quantityKindFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(quantityKindFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("quantityKind"u8); - writer.WriteStringValue(quantityKindFactor.QuantityKind); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(quantityKindFactor.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(quantityKindFactor.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index 4ad6a83b7..b7edfc24c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,370 +51,441 @@ namespace CDP4JsonSerializer public class RatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RatioScale ratioScale) + { + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(mappingToReferenceScaleItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(valueDefinitionItem); } - + writer.WriteEndArray(); + break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(mappingToReferenceScaleItem); } - break; - case "ismaximuminclusive": - var allowedVersionsForIsMaximumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - if(!allowedVersionsForIsMaximumInclusive.Contains(requestedVersion)) + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueDefinitionItem); } - writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteEndArray(); - if(value != null) + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ratioScale.Actor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(ratioScale.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isminimuminclusive": - var allowedVersionsForIsMinimumInclusive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsMinimumInclusive.Contains(requestedVersion)) + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "mappingtoreferencescale": - var allowedVersionsForMappingToReferenceScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForMappingToReferenceScale.Contains(requestedVersion)) + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("mappingToReferenceScale"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListMappingToReferenceScale) + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "maximumpermissiblevalue": - var allowedVersionsForMaximumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForMaximumPermissibleValue.Contains(requestedVersion)) + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(mappingToReferenceScaleItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); + break; - case "minimumpermissiblevalue": - var allowedVersionsForMinimumPermissibleValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForMinimumPermissibleValue.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -421,50 +493,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,103 +529,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "negativevalueconnotation": - var allowedVersionsForNegativeValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForNegativeValueConnotation.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("negativeValueConnotation"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "numberset": - var allowedVersionsForNumberSet = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForNumberSet.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) { - return; + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - - writer.WritePropertyName("numberSet"u8); - if(value != null) - { - writer.WriteStringValue(((NumberSetKind)value).ToString()); - } - else + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "positivevalueconnotation": - var allowedVersionsForPositiveValueConnotation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForPositiveValueConnotation.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) { - return; + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - - writer.WritePropertyName("positiveValueConnotation"u8); - if(value != null) + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue((string)value); + return; } - else + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) { - writer.WriteNullValue(); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + + writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -576,25 +619,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -602,23 +637,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -626,25 +655,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("unit"u8); + writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteBooleanValue((bool)value); } else { @@ -652,421 +673,275 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "valuedefinition": - var allowedVersionsForValueDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueDefinition.Contains(requestedVersion)) + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("valueDefinition"u8); + writer.WriteStartArray("mappingToReferenceScale"u8); - if(value is IEnumerable objectListValueDefinition) + if(value is IEnumerable objectListMappingToReferenceScale) { - foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue(mappingToReferenceScaleItem); } } writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RatioScale ratioScale) - { - throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ratioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ratioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MaximumPermissibleValue); writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MinimumPermissibleValue); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ratioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ratioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ratioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ratioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ratioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ratioScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ratioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ratioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ratioScale.Name); writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ratioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ratioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ratioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ratioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ratioScale.ShortName); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("numberSet"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((NumberSetKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ratioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ratioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ratioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ratioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ratioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ratioScale.PositiveValueConnotation); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ratioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ratioScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ratioScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(valueDefinitionItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RatioScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(ratioScale.Actor.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(ratioScale.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("unit"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ratioScale.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(ratioScale.IsDeprecated); - writer.WritePropertyName("isMaximumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); - writer.WritePropertyName("isMinimumInclusive"u8); - writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) { - writer.WriteStringValue(mappingToReferenceScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("maximumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MaximumPermissibleValue); - writer.WritePropertyName("minimumPermissibleValue"u8); - writer.WriteStringValue(ratioScale.MinimumPermissibleValue); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ratioScale.Name); - writer.WritePropertyName("negativeValueConnotation"u8); - writer.WriteStringValue(ratioScale.NegativeValueConnotation); - writer.WritePropertyName("numberSet"u8); - writer.WriteStringValue(ratioScale.NumberSet.ToString()); - writer.WritePropertyName("positiveValueConnotation"u8); - writer.WriteStringValue(ratioScale.PositiveValueConnotation); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ratioScale.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ratioScale.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ratioScale.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(ratioScale.Unit); writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListValueDefinition) { - writer.WriteStringValue(valueDefinitionItem); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index d86691242..c0b47518b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,614 +51,254 @@ namespace CDP4JsonSerializer public class ReferenceSourceSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not ReferenceSource referenceSource) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) - { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); writer.WritePropertyName("isDeprecated"u8); - - if(value != null) + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteNumberValue(referenceSource.PublicationYear.Value); } else { writer.WriteNullValue(); } - break; - case "language": - var allowedVersionsForLanguage = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguage.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("publishedIn"u8); - writer.WritePropertyName("language"u8); - - if(value != null) + if(referenceSource.PublishedIn.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(referenceSource.PublishedIn.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("publisher"u8); - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) + if(referenceSource.Publisher.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(referenceSource.Publisher.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); - writer.WritePropertyName("name"u8); - - if(value != null) + if(referenceSource.VersionDate.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); break; - case "publicationyear": - var allowedVersionsForPublicationYear = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForPublicationYear.Contains(requestedVersion)) + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("publicationYear"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "publishedin": - var allowedVersionsForPublishedIn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); - if(!allowedVersionsForPublishedIn.Contains(requestedVersion)) + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("publishedIn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "publisher": - var allowedVersionsForPublisher = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForPublisher.Contains(requestedVersion)) + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("publisher"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteNumberValue(referenceSource.PublicationYear.Value); } else { writer.WriteNullValue(); } - break; - case "versiondate": - var allowedVersionsForVersionDate = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForVersionDate.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("publishedIn"u8); - writer.WritePropertyName("versionDate"u8); - - if(value != null) + if(referenceSource.PublishedIn.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(referenceSource.PublishedIn.Value); } else { writer.WriteNullValue(); } - break; - case "versionidentifier": - var allowedVersionsForVersionIdentifier = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForVersionIdentifier.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("publisher"u8); - writer.WritePropertyName("versionIdentifier"u8); - - if(value != null) + if(referenceSource.Publisher.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(referenceSource.Publisher.Value); } else { writer.WriteNullValue(); } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferenceSource"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ReferenceSource referenceSource) - { - throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); - return; - } + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); - writer.WriteStartObject(); + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.0.0"); + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -666,6 +307,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); writer.WriteStartArray("category"u8); @@ -676,6 +318,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -686,6 +329,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -694,12 +356,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(referenceSource.IsDeprecated); writer.WritePropertyName("language"u8); writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referenceSource.Name); writer.WritePropertyName("publicationYear"u8); @@ -739,6 +404,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(referenceSource.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); writer.WritePropertyName("versionDate"u8); if(referenceSource.VersionDate.HasValue) @@ -753,8 +420,19 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("versionIdentifier"u8); writer.WriteStringValue(referenceSource.VersionIdentifier); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referenceSource.Actor.HasValue) + { + writer.WriteStringValue(referenceSource.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -763,6 +441,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); writer.WriteStartArray("category"u8); @@ -773,6 +452,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -783,6 +463,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -791,6 +472,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -799,6 +481,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -807,6 +490,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -854,6 +538,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(referenceSource.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); writer.WritePropertyName("versionDate"u8); if(referenceSource.VersionDate.HasValue) @@ -865,260 +551,459 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WritePropertyName("versionIdentifier"u8); - writer.WriteStringValue(referenceSource.VersionIdentifier); + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "language": + if(!AllowedVersionsPerProperty["language"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referenceSource.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referenceSource.IsDeprecated); writer.WritePropertyName("language"u8); - writer.WriteStringValue(referenceSource.Language); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referenceSource.Name); - writer.WritePropertyName("publicationYear"u8); - - if(referenceSource.PublicationYear.HasValue) + + if(value != null) { - writer.WriteNumberValue(referenceSource.PublicationYear.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("publishedIn"u8); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.PublishedIn.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.PublishedIn.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("publisher"u8); + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.Publisher.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.Publisher.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referenceSource.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referenceSource.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(referenceSource.ThingPreference); - writer.WritePropertyName("versionDate"u8); + break; + case "publicationyear": + if(!AllowedVersionsPerProperty["publicationYear"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.VersionDate.HasValue) + writer.WritePropertyName("publicationYear"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("versionIdentifier"u8); - writer.WriteStringValue(referenceSource.VersionIdentifier); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ReferenceSource for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "publishedin": + if(!AllowedVersionsPerProperty["publishedIn"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.Actor.HasValue) + writer.WritePropertyName("publishedIn"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.Actor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "publisher": + if(!AllowedVersionsPerProperty["publisher"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("publisher"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referenceSource.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referenceSource.IsDeprecated); - writer.WritePropertyName("language"u8); - writer.WriteStringValue(referenceSource.Language); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referenceSource.Name); - writer.WritePropertyName("publicationYear"u8); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.PublicationYear.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteNumberValue(referenceSource.PublicationYear.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("publishedIn"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.PublishedIn.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.PublishedIn.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("publisher"u8); + break; + case "versiondate": + if(!AllowedVersionsPerProperty["versionDate"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.Publisher.HasValue) + writer.WritePropertyName("versionDate"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.Publisher.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referenceSource.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referenceSource.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(referenceSource.ThingPreference); - writer.WritePropertyName("versionDate"u8); + break; + case "versionidentifier": + if(!AllowedVersionsPerProperty["versionIdentifier"].Contains(requestedVersion)) + { + return; + } - if(referenceSource.VersionDate.HasValue) + writer.WritePropertyName("versionIdentifier"u8); + + if(value != null) { - writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("versionIdentifier"u8); - writer.WriteStringValue(referenceSource.VersionIdentifier); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferenceSource"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "language", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publicationYear", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedIn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publisher", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "versionDate", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "versionIdentifier", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index 48553ff25..36b9ef62a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,231 +51,500 @@ namespace CDP4JsonSerializer public class ReferencerRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - if(value is IEnumerable objectListAlias) + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(referencedCategoryItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(referencedCategoryItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referencedCategoryItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referencerRule.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(referencerRule.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -292,15 +562,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "maxreferenced": - var allowedVersionsForMaxReferenced = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMaxReferenced.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["maxReferenced"].Contains(requestedVersion)) { return; } @@ -318,15 +580,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minreferenced": - var allowedVersionsForMinReferenced = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForMinReferenced.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["minReferenced"].Contains(requestedVersion)) { return; } @@ -344,14 +598,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -369,15 +616,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -395,15 +634,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedcategory": - var allowedVersionsForReferencedCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencedCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencedCategory"].Contains(requestedVersion)) { return; } @@ -421,15 +652,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "referencingcategory": - var allowedVersionsForReferencingCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencingCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencingCategory"].Contains(requestedVersion)) { return; } @@ -447,15 +670,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -473,15 +688,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -499,13 +706,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -528,317 +729,29 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ReferencerRule referencerRule) - { - throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referencerRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referencerRule.IsDeprecated); - writer.WritePropertyName("maxReferenced"u8); - writer.WriteNumberValue(referencerRule.MaxReferenced); - writer.WritePropertyName("minReferenced"u8); - writer.WriteNumberValue(referencerRule.MinReferenced); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("referencingCategory"u8); - writer.WriteStringValue(referencerRule.ReferencingCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referencerRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referencerRule.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referencerRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referencerRule.IsDeprecated); - writer.WritePropertyName("maxReferenced"u8); - writer.WriteNumberValue(referencerRule.MaxReferenced); - writer.WritePropertyName("minReferenced"u8); - writer.WriteNumberValue(referencerRule.MinReferenced); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("referencingCategory"u8); - writer.WriteStringValue(referencerRule.ReferencingCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referencerRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referencerRule.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referencerRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referencerRule.IsDeprecated); - writer.WritePropertyName("maxReferenced"u8); - writer.WriteNumberValue(referencerRule.MaxReferenced); - writer.WritePropertyName("minReferenced"u8); - writer.WriteNumberValue(referencerRule.MinReferenced); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("referencingCategory"u8); - writer.WriteStringValue(referencerRule.ReferencingCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referencerRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referencerRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(referencerRule.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ReferencerRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(referencerRule.Actor.HasValue) - { - writer.WriteStringValue(referencerRule.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(referencerRule.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(referencerRule.IsDeprecated); - writer.WritePropertyName("maxReferenced"u8); - writer.WriteNumberValue(referencerRule.MaxReferenced); - writer.WritePropertyName("minReferenced"u8); - writer.WriteNumberValue(referencerRule.MinReferenced); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("referencingCategory"u8); - writer.WriteStringValue(referencerRule.ReferencingCategory); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(referencerRule.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(referencerRule.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(referencerRule.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index c7a9b5bf9..dd52a2064 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,213 @@ namespace CDP4JsonSerializer /// public class RelationalExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not RelationalExpression relationalExpression) + { + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationalExpression.Actor.HasValue) + { + writer.WriteStringValue(relationalExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +264,7 @@ public class RelationalExpressionSerializer : BaseThingSerializer, IThingSeriali /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +272,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +290,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +308,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +326,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +344,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +362,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +380,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -239,15 +398,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relationaloperator": - var allowedVersionsForRelationalOperator = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelationalOperator.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relationalOperator"].Contains(requestedVersion)) { return; } @@ -265,15 +416,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,15 +434,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -317,13 +452,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -341,15 +470,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -362,205 +483,23 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not RelationalExpression relationalExpression) - { - throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationalExpression.Iid); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationalExpression.ParameterType); - writer.WritePropertyName("relationalOperator"u8); - writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationalExpression.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationalExpression.Scale.HasValue) - { - writer.WriteStringValue(relationalExpression.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationalExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationalExpression.ParameterType); - writer.WritePropertyName("relationalOperator"u8); - writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationalExpression.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationalExpression.Scale.HasValue) - { - writer.WriteStringValue(relationalExpression.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationalExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationalExpression.ParameterType); - writer.WritePropertyName("relationalOperator"u8); - writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationalExpression.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationalExpression.Scale.HasValue) - { - writer.WriteStringValue(relationalExpression.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(relationalExpression.ThingPreference); - writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RelationalExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(relationalExpression.Actor.HasValue) - { - writer.WriteStringValue(relationalExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationalExpression.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationalExpression.ParameterType); - writer.WritePropertyName("relationalOperator"u8); - writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationalExpression.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationalExpression.Scale.HasValue) - { - writer.WriteStringValue(relationalExpression.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(relationalExpression.ThingPreference); - writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationalOperator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index a7653761d..751c35b7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,182 @@ namespace CDP4JsonSerializer /// public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not RelationshipParameterValue relationshipParameterValue) + { + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationshipParameterValue.Actor.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +233,7 @@ public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingS /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +241,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +259,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +277,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +295,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -186,14 +331,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -211,14 +349,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -236,14 +367,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -261,14 +385,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -286,13 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -310,14 +421,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -330,174 +434,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not RelationshipParameterValue relationshipParameterValue) - { - throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationshipParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationshipParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationshipParameterValue.Scale.HasValue) - { - writer.WriteStringValue(relationshipParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationshipParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationshipParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationshipParameterValue.Scale.HasValue) - { - writer.WriteStringValue(relationshipParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(relationshipParameterValue.ThingPreference); - writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RelationshipParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(relationshipParameterValue.Actor.HasValue) - { - writer.WriteStringValue(relationshipParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(relationshipParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(relationshipParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(relationshipParameterValue.Scale.HasValue) - { - writer.WriteStringValue(relationshipParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(relationshipParameterValue.ThingPreference); - writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index c9ae82ee9..8aabd337b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,305 +51,382 @@ namespace CDP4JsonSerializer public class RequestForDeviationSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForDeviation.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(requestForDeviation.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WriteStartArray("discussion"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDiscussion) + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) { - return; + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("relatedThing"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(relatedThingItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -360,24 +438,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("author"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -385,24 +474,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -410,24 +510,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,24 +528,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -460,49 +546,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) - { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -510,74 +564,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) { - writer.WriteStringValue((string)value); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListSourceAnnotation) + if(value is IEnumerable objectListExcludedPerson) { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(sourceAnnotationItem); + writer.WriteStringValue(excludedPersonItem); } } writer.WriteEndArray(); break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("status"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -585,19 +636,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -609,24 +654,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -634,345 +672,202 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForDeviation"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RequestForDeviation requestForDeviation) - { - throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForDeviation.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForDeviation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForDeviation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForDeviation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForDeviation.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + + if(value != null) { - writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForDeviation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForDeviation.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForDeviation.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForDeviation.Title); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForDeviation.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForDeviation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForDeviation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForDeviation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForDeviation.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForDeviation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForDeviation.ShortName); writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForDeviation.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requestForDeviation.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForDeviation.Title); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForDeviation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } - if(requestForDeviation.Actor.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(requestForDeviation.Actor.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForDeviation.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForDeviation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForDeviation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForDeviation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForDeviation.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForDeviation.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForDeviation.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForDeviation.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requestForDeviation.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForDeviation.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForDeviation"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index 322fed874..e083024a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,305 +51,382 @@ namespace CDP4JsonSerializer public class RequestForWaiverSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(value is IEnumerable objectListCategory) + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(sourceAnnotationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForWaiver.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(requestForWaiver.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WriteStartArray("discussion"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDiscussion) + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) { - return; + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("relatedThing"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(relatedThingItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -360,24 +438,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("author"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -385,24 +474,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -410,24 +510,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -435,24 +528,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -460,49 +546,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) - { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -510,74 +564,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) { - writer.WriteStringValue((string)value); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListSourceAnnotation) + if(value is IEnumerable objectListExcludedPerson) { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(sourceAnnotationItem); + writer.WriteStringValue(excludedPersonItem); } } writer.WriteEndArray(); break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("status"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -585,19 +636,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -609,24 +654,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -634,345 +672,202 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForWaiver"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RequestForWaiver requestForWaiver) - { - throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForWaiver.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForWaiver.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForWaiver.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForWaiver.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForWaiver.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + + if(value != null) { - writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForWaiver.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForWaiver.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForWaiver.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForWaiver.Title); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForWaiver.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForWaiver.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForWaiver.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForWaiver.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForWaiver.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForWaiver.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForWaiver.ShortName); writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(sourceAnnotationItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForWaiver.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requestForWaiver.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForWaiver.Title); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RequestForWaiver for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } - if(requestForWaiver.Actor.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(requestForWaiver.Actor.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(requestForWaiver.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(requestForWaiver.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(discussionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requestForWaiver.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(requestForWaiver.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requestForWaiver.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requestForWaiver.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requestForWaiver.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(requestForWaiver.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requestForWaiver.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(requestForWaiver.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForWaiver"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 489a7dab0..5edc2e7d7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,365 +51,461 @@ namespace CDP4JsonSerializer public class RequirementSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not Requirement requirement) + { + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List + Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) { - "1.3.0", - }; + writer.WriteStringValue(categoryItem); + } - if(!allowedVersionsForActor.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requirement.Group.Value); } else { writer.WriteNullValue(); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - if(value is IEnumerable objectListAlias) + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(parameterValueItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(requirement.Group.Value); } else { writer.WriteNullValue(); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - if(value is IEnumerable objectListDefinition) + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(parameterValueItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "group": - var allowedVersionsForGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForGroup.Contains(requestedVersion)) + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("group"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requirement.Group.Value); } else { writer.WriteNullValue(); } - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(parameterValueItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("parametricConstraint"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(parametricConstraintItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirement.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requirement.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(requirement.Group.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(parameterValueItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(parametricConstraintItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -420,77 +517,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "parametervalue": - var allowedVersionsForParameterValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("parameterValue"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListParameterValue) + if(value is IEnumerable objectListAlias) { - foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterValueItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "parametricconstraint": - var allowedVersionsForParametricConstraint = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParametricConstraint.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("parametricConstraint"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListParametricConstraint) + if(value is IEnumerable objectListCategory) { - foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteOrderedItem(parametricConstraintItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -498,49 +571,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("group"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -548,415 +643,234 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Requirement"); - } - } + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Requirement requirement) - { - throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(categoryItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("group"u8); - - if(requirement.Group.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(requirement.Group.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirement.Iid); writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirement.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirement.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(parameterValueItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(parametricConstraintItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirement.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirement.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("group"u8); - - if(requirement.Group.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(requirement.Group.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirement.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirement.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(parameterValueItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + else { - writer.WriteOrderedItem(parametricConstraintItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirement.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirement.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("parameterValue"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterValue) { - writer.WriteStringValue(categoryItem); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "parametricconstraint": + if(!AllowedVersionsPerProperty["parametricConstraint"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("parametricConstraint"u8); - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParametricConstraint) { - writer.WriteStringValue(excludedDomainItem); + foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("group"u8); - - if(requirement.Group.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(requirement.Group.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirement.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirement.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirement.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteOrderedItem(parametricConstraintItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirement.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirement.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirement.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Requirement for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(requirement.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(requirement.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("group"u8); - - if(requirement.Group.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(requirement.Group.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirement.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirement.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirement.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(parametricConstraintItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirement.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirement.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirement.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Requirement"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parametricConstraint", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 21e384c1f..cd791bb98 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,182 @@ namespace CDP4JsonSerializer /// public class RequirementsContainerParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) + { + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsContainerParameterValue.Actor.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +233,7 @@ public class RequirementsContainerParameterValueSerializer : BaseThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +241,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +259,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +277,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +295,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -186,14 +331,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -211,14 +349,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -236,14 +367,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -261,14 +385,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -286,13 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -310,14 +421,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -330,174 +434,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) - { - throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsContainerParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(requirementsContainerParameterValue.Scale.HasValue) - { - writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsContainerParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(requirementsContainerParameterValue.Scale.HasValue) - { - writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); - writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(requirementsContainerParameterValue.Actor.HasValue) - { - writer.WriteStringValue(requirementsContainerParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsContainerParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(requirementsContainerParameterValue.Scale.HasValue) - { - writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); - writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 496d84ec6..31cc56d6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,529 +51,274 @@ namespace CDP4JsonSerializer public class RequirementsGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(groupItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); - if(value is IEnumerable objectListDefinition) + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(groupItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(parameterValueItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "group": - var allowedVersionsForGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForGroup.Contains(requestedVersion)) + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("group"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListGroup) + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("group"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(groupItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "parametervalue": - var allowedVersionsForParameterValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValue.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(requirementsGroup.Owner); writer.WriteStartArray("parameterValue"u8); - if(value is IEnumerable objectListParameterValue) - { - foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } - } - - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterValueItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + if(requirementsGroup.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(requirementsGroup.Actor.Value); } else { writer.WriteNullValue(); } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsGroup"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RequirementsGroup requirementsGroup) - { - throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsGroup.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsGroup.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsGroup.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsGroup.ShortName); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.1.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -581,6 +327,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -589,6 +336,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -599,6 +347,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -607,6 +356,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -615,6 +365,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) @@ -623,6 +374,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -631,6 +383,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -647,194 +400,369 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); + writer.WriteStartArray("alias"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(groupItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsGroup.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsGroup.Owner); - writer.WriteStartArray("parameterValue"u8); + writer.WriteStartArray("category"u8); - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListCategory) { - writer.WriteStringValue(parameterValueItem); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsGroup.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsGroup.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } - if(requirementsGroup.Actor.HasValue) + writer.WritePropertyName("classKind"u8); + + if(value != null) { - writer.WriteStringValue(requirementsGroup.Actor.Value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("definition"u8); - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(categoryItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGroup) { - writer.WriteStringValue(groupItem); + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsGroup.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsGroup.Name); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsGroup.Owner); - writer.WriteStartArray("parameterValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterValueItem); + return; } + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsGroup.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsGroup.ShortName); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsGroup.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsGroup"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 3f9c5533f..a237a7fb8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,364 +51,435 @@ namespace CDP4JsonSerializer public class RequirementsSpecificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(groupItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("requirement"u8); - if(value is IEnumerable objectListAlias) + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(requirementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(groupItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(parameterValueItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(requirementItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "group": - var allowedVersionsForGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForGroup.Contains(requestedVersion)) + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("group"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListGroup) + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(groupItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requirementItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsSpecification.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(requirementsSpecification.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(groupItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(parameterValueItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(requirementItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -419,76 +491,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "parametervalue": - var allowedVersionsForParameterValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterValue.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("parameterValue"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListParameterValue) + if(value is IEnumerable objectListAlias) { - foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterValueItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "requirement": - var allowedVersionsForRequirement = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRequirement.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("requirement"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListRequirement) + if(value is IEnumerable objectListCategory) { - foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(requirementItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -496,437 +545,306 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue((string)value); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - else + + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsSpecification"); - } - } + writer.WriteStartArray("group"u8); - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RequirementsSpecification requirementsSpecification) - { - throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGroup) { - writer.WriteStringValue(aliasItem); + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(groupItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsSpecification.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsSpecification.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(requirementItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsSpecification.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsSpecification.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(groupItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsSpecification.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsSpecification.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(parameterValueItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(requirementItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsSpecification.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsSpecification.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("owner"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); + writer.WriteStartArray("parameterValue"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParameterValue) { - writer.WriteStringValue(groupItem); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "requirement": + if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsSpecification.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsSpecification.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); + writer.WriteStartArray("requirement"u8); - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRequirement) { - writer.WriteStringValue(parameterValueItem); + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(requirementItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsSpecification.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsSpecification.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsSpecification.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RequirementsSpecification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(requirementsSpecification.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(requirementsSpecification.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(groupItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(requirementsSpecification.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(requirementsSpecification.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(parameterValueItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(requirementItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(requirementsSpecification.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(requirementsSpecification.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(requirementsSpecification.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsSpecification"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index ae3bf64b7..bd78f1344 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,305 +51,445 @@ namespace CDP4JsonSerializer public class ReviewItemDiscrepancySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) + { + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.1.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "approvedby": - var allowedVersionsForApprovedBy = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForApprovedBy.Contains(requestedVersion)) + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(discussionItem); } - writer.WriteStartArray("approvedBy"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListApprovedBy) + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); - if(value is IEnumerable objectListCategory) + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(solutionItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); break; - case "classification": - var allowedVersionsForClassification = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForClassification.Contains(requestedVersion)) + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } - writer.WritePropertyName("classification"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(discussionItem); } - break; - case "classkind": - var allowedVersionsForClassKind = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("relatedThing"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(relatedThingItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(solutionItem); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(sourceAnnotationItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(reviewItemDiscrepancy.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(reviewItemDiscrepancy.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("approvedBy"u8); - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WriteStartArray("discussion"u8); - if(value is IEnumerable objectListDiscussion) + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) { - foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + writer.WriteStringValue(discussionItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { - return; + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("relatedThing"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteNullValue(); + } - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("approvedBy"u8); - if(value is IEnumerable objectListExcludedPerson) + if(value is IEnumerable objectListApprovedBy) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(approvedByItem); } } writer.WriteEndArray(); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("author"u8); if(value != null) { @@ -360,24 +501,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); + writer.WritePropertyName("classification"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); } else { @@ -385,24 +537,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -410,24 +555,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("owner"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue((string)value); } else { @@ -435,24 +573,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -460,49 +591,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "relatedthing": - var allowedVersionsForRelatedThing = new List + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("discussion"u8); - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListRelatedThing) + if(value is IEnumerable objectListExcludedDomain) { - foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(relatedThingItem); + writer.WriteStringValue(excludedDomainItem); } } writer.WriteEndArray(); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -510,20 +663,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("languageCode"u8); if(value != null) { @@ -535,74 +681,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "solution": - var allowedVersionsForSolution = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSolution.Contains(requestedVersion)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("solution"u8); - - if(value is IEnumerable objectListSolution) - { - foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } - } - - writer.WriteEndArray(); - break; - case "sourceannotation": - var allowedVersionsForSourceAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSourceAnnotation.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) - { - foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - } - - writer.WriteEndArray(); - break; - case "status": - var allowedVersionsForStatus = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("status"u8); + writer.WritePropertyName("modifiedOn"u8); if(value != null) { - writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -610,23 +699,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("owner"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -634,24 +717,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "title": - var allowedVersionsForTitle = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForTitle.Contains(requestedVersion)) + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("title"u8); + writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -659,369 +735,185 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ReviewItemDiscrepancy"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) - { - throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRelatedThing) { - writer.WriteStringValue(excludedDomainItem); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(relatedThingItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(solutionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(sourceAnnotationItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Title); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + case "solution": + if(!AllowedVersionsPerProperty["solution"].Contains(requestedVersion)) { - writer.WriteStringValue(approvedByItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("solution"u8); - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSolution) { - writer.WriteStringValue(categoryItem); + foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) { - writer.WriteStringValue(discussionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("sourceAnnotation"u8); - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSourceAnnotation) { - writer.WriteStringValue(excludedDomainItem); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("status"u8); + + if(value != null) { - writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(sourceAnnotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Title); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(reviewItemDiscrepancy.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(reviewItemDiscrepancy.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classification"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Owner); - writer.WritePropertyName("primaryAnnotatedThing"u8); - - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + writer.WritePropertyName("title"u8); + + if(value != null) { - writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); - writer.WritePropertyName("title"u8); - writer.WriteStringValue(reviewItemDiscrepancy.Title); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReviewItemDiscrepancy"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "solution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index 4da2b357e..5cf08a6b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,317 +51,341 @@ namespace CDP4JsonSerializer public class RuleVerificationListSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not RuleVerificationList ruleVerificationList) + { + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - if(value is IEnumerable objectListAlias) + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteOrderedItem(ruleVerificationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListDefinition) + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteOrderedItem(ruleVerificationItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(ruleVerificationItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleVerificationList.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(ruleVerificationList.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "owner": - var allowedVersionsForOwner = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForOwner.Contains(requestedVersion)) + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("owner"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); + writer.WriteOrderedItem(ruleVerificationItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -368,51 +393,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "ruleverification": - var allowedVersionsForRuleVerification = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRuleVerification.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("ruleVerification"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListRuleVerification) + if(value is IEnumerable objectListAlias) { - foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteOrderedItem(ruleVerificationItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -420,323 +429,248 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteNullValue(); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + + writer.WriteEndArray(); break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleVerificationList"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not RuleVerificationList ruleVerificationList) - { - throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(definitionItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleVerificationList.Iid); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ruleVerificationList.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(ruleVerificationList.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteOrderedItem(ruleVerificationItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ruleVerificationList.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(definitionItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleVerificationList.Iid); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ruleVerificationList.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(ruleVerificationList.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(ruleVerificationItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ruleVerificationList.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(aliasItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleVerificationList.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ruleVerificationList.Name); writer.WritePropertyName("owner"u8); - writer.WriteStringValue(ruleVerificationList.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + + if(value != null) { - writer.WriteOrderedItem(ruleVerificationItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ruleVerificationList.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ruleVerificationList.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RuleVerificationList for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(ruleVerificationList.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(ruleVerificationList.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "ruleverification": + if(!AllowedVersionsPerProperty["ruleVerification"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("ruleVerification"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRuleVerification) { - writer.WriteStringValue(definitionItem); + foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleVerificationList.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ruleVerificationList.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(ruleVerificationList.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteOrderedItem(ruleVerificationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(ruleVerificationList.ShortName); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ruleVerificationList.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleVerificationList"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index e7f25e745..a37d9bcd0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,193 @@ namespace CDP4JsonSerializer /// public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleViolation.Actor.HasValue) + { + writer.WriteStringValue(ruleViolation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +244,7 @@ public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +252,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +270,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,15 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "description": - var allowedVersionsForDescription = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDescription.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) { return; } @@ -138,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -163,14 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -188,15 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +378,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -265,13 +396,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -289,15 +414,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "violatingthing": - var allowedVersionsForViolatingThing = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForViolatingThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["violatingThing"].Contains(requestedVersion)) { return; } @@ -320,181 +437,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not RuleViolation ruleViolation) - { - throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleViolation.ClassKind.ToString()); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(ruleViolation.Description); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleViolation.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleViolation.ClassKind.ToString()); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleViolation.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleViolation.ClassKind.ToString()); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleViolation.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ruleViolation.ThingPreference); - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing RuleViolation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(ruleViolation.Actor.HasValue) - { - writer.WriteStringValue(ruleViolation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(ruleViolation.ClassKind.ToString()); - writer.WritePropertyName("description"u8); - writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(ruleViolation.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(ruleViolation.ThingPreference); - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violatingThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index 1ba4dc61f..80cb84791 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,259 @@ namespace CDP4JsonSerializer /// public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sampledFunctionParameterType.Actor.HasValue) + { + writer.WriteStringValue(sampledFunctionParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +310,7 @@ public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThin /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,13 +336,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "alias": - var allowedVersionsForAlias = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } @@ -110,13 +354,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "category": - var allowedVersionsForCategory = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -134,13 +372,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -158,13 +390,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - var allowedVersionsForDefinition = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } @@ -182,13 +408,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "degreeofinterpolation": - var allowedVersionsForDegreeOfInterpolation = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDegreeOfInterpolation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["degreeOfInterpolation"].Contains(requestedVersion)) { return; } @@ -206,13 +426,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "dependentparametertype": - var allowedVersionsForDependentParameterType = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDependentParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["dependentParameterType"].Contains(requestedVersion)) { return; } @@ -229,15 +443,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -255,14 +462,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -280,13 +480,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } @@ -304,13 +498,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -328,13 +516,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "independentparametertype": - var allowedVersionsForIndependentParameterType = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIndependentParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["independentParameterType"].Contains(requestedVersion)) { return; } @@ -352,13 +534,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "interpolationperiod": - var allowedVersionsForInterpolationPeriod = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForInterpolationPeriod.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["interpolationPeriod"].Contains(requestedVersion)) { return; } @@ -366,13 +542,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteString("interpolationPeriod"u8, ((ValueArray)value).ToJsonString()); break; case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } @@ -390,14 +560,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -415,13 +578,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -439,13 +596,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -463,13 +614,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -487,13 +632,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - var allowedVersionsForSymbol = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { return; } @@ -511,13 +650,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -540,241 +673,31 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not SampledFunctionParameterType sampledFunctionParameterType) - { - throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.2.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SampledFunctionParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("degreeOfInterpolation"u8); - - if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) - { - writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("dependentParameterType"u8); - - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(dependentParameterTypeItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(sampledFunctionParameterType.Iid); - writer.WriteStartArray("independentParameterType"u8); - - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(independentParameterTypeItem); - } - - writer.WriteEndArray(); - writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(sampledFunctionParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(sampledFunctionParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(sampledFunctionParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SampledFunctionParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(sampledFunctionParameterType.Actor.HasValue) - { - writer.WriteStringValue(sampledFunctionParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("degreeOfInterpolation"u8); - - if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) - { - writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("dependentParameterType"u8); - - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(dependentParameterTypeItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(sampledFunctionParameterType.Iid); - writer.WriteStartArray("independentParameterType"u8); - - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(independentParameterTypeItem); - } - - writer.WriteEndArray(); - writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(sampledFunctionParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(sampledFunctionParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(sampledFunctionParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.2.0", "1.3.0" }}, + { "category", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.2.0", "1.3.0" }}, + { "degreeOfInterpolation", new []{ "1.2.0", "1.3.0" }}, + { "dependentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "independentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "interpolationPeriod", new []{ "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index e65485253..5852aa471 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) + { + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleReferenceQuantityValue.Actor.HasValue) + { + writer.WriteStringValue(scaleReferenceQuantityValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThing /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -265,13 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -289,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) - { - throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Scale); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Value); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Scale); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Value); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Scale); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Value); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(scaleReferenceQuantityValue.Actor.HasValue) - { - writer.WriteStringValue(scaleReferenceQuantityValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Scale); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(scaleReferenceQuantityValue.Value); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index 492f146e2..b1adb3c9b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,424 +51,112 @@ namespace CDP4JsonSerializer public class ScaleValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not ScaleValueDefinition scaleValueDefinition) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(scaleValueDefinition.Name); writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); writer.WritePropertyName("shortName"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForValue.Contains(requestedVersion)) + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("value"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleValueDefinition"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not ScaleValueDefinition scaleValueDefinition) - { - throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(excludedDomainItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -476,8 +165,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(scaleValueDefinition.Name); writer.WritePropertyName("revisionNumber"u8); @@ -487,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(scaleValueDefinition.Value); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +189,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -507,6 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -515,6 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -523,6 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -531,6 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -541,11 +238,24 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); writer.WritePropertyName("value"u8); writer.WriteStringValue(scaleValueDefinition.Value); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleValueDefinition.Actor.HasValue) + { + writer.WriteStringValue(scaleValueDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -554,6 +264,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -564,6 +275,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -572,6 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -580,6 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -588,6 +302,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -603,82 +318,304 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(scaleValueDefinition.Value); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ScaleValueDefinition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(scaleValueDefinition.Actor.HasValue) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(scaleValueDefinition.Actor.Value); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("alias"u8); - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(aliasItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(scaleValueDefinition.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("name"u8); - writer.WriteStringValue(scaleValueDefinition.Name); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(scaleValueDefinition.ShortName); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(scaleValueDefinition.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("value"u8); - writer.WriteStringValue(scaleValueDefinition.Value); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleValueDefinition"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 49fb9fa52..3d4aa0bf9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,218 @@ namespace CDP4JsonSerializer /// public class SectionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Section section) + { + throw new ArgumentException("The thing shall be a Section", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(section.Actor.HasValue) + { + writer.WriteStringValue(section.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +269,7 @@ public class SectionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +277,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +295,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -111,14 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +331,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -161,14 +349,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -186,14 +367,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -211,14 +385,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -236,14 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -261,14 +421,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -286,14 +439,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -311,14 +457,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "page": - var allowedVersionsForPage = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPage.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["page"].Contains(requestedVersion)) { return; } @@ -336,14 +475,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,14 +493,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +511,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,204 +534,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Section section) - { - throw new ArgumentException("The thing shall be a Section", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(section.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(section.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(section.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(pageItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(section.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(section.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(section.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(section.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(section.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(pageItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(section.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(section.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(section.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Section for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(section.Actor.HasValue) - { - writer.WriteStringValue(section.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(section.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(section.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(section.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(pageItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(section.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(section.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(section.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "page", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index c5318bfc6..2ced7f763 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,597 +51,195 @@ namespace CDP4JsonSerializer public class SharedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not SharedStyle sharedStyle) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); + return; + } - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "fillcolor": - var allowedVersionsForFillColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFillColor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("fillColor"u8); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "fillopacity": - var allowedVersionsForFillOpacity = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForFillOpacity.Contains(requestedVersion)) + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("fillOpacity"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((float)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "fontbold": - var allowedVersionsForFontBold = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontBold.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fillColor"u8); - writer.WritePropertyName("fontBold"u8); - - if(value != null) + if(sharedStyle.FillColor.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(sharedStyle.FillColor.Value); } else { writer.WriteNullValue(); } - break; - case "fontcolor": - var allowedVersionsForFontColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontColor.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fillOpacity"u8); - writer.WritePropertyName("fontColor"u8); - - if(value != null) + if(sharedStyle.FillOpacity.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); } else { writer.WriteNullValue(); } - break; - case "fontitalic": - var allowedVersionsForFontItalic = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontItalic.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontBold"u8); - writer.WritePropertyName("fontItalic"u8); - - if(value != null) + if(sharedStyle.FontBold.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteBooleanValue(sharedStyle.FontBold.Value); } else { writer.WriteNullValue(); } - break; - case "fontname": - var allowedVersionsForFontName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontName.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontColor"u8); - writer.WritePropertyName("fontName"u8); - - if(value != null) + if(sharedStyle.FontColor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(sharedStyle.FontColor.Value); } else { writer.WriteNullValue(); } - break; - case "fontsize": - var allowedVersionsForFontSize = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontSize.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontItalic"u8); - writer.WritePropertyName("fontSize"u8); - - if(value != null) + if(sharedStyle.FontItalic.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); } else { writer.WriteNullValue(); } - break; - case "fontstrokethrough": - var allowedVersionsForFontStrokeThrough = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontStrokeThrough.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); - writer.WritePropertyName("fontStrokeThrough"u8); - - if(value != null) + if(sharedStyle.FontSize.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteNumberValue(sharedStyle.FontSize.Value); } else { writer.WriteNullValue(); } - break; - case "fontunderline": - var allowedVersionsForFontUnderline = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForFontUnderline.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontStrokeThrough"u8); - writer.WritePropertyName("fontUnderline"u8); - - if(value != null) + if(sharedStyle.FontStrokeThrough.HasValue) { - writer.WriteBooleanValue((bool)value); + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); } else { writer.WriteNullValue(); } - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("fontUnderline"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(sharedStyle.FontUnderline.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(sharedStyle.Name); writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "strokecolor": - var allowedVersionsForStrokeColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeColor.Contains(requestedVersion)) - { - return; - } - + writer.WriteNumberValue(sharedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "strokeopacity": - var allowedVersionsForStrokeOpacity = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeOpacity.Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeOpacity"u8); - - if(value != null) + if(sharedStyle.StrokeColor.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteStringValue(sharedStyle.StrokeColor.Value); } else { writer.WriteNullValue(); } - break; - case "strokewidth": - var allowedVersionsForStrokeWidth = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStrokeWidth.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("strokeOpacity"u8); - writer.WritePropertyName("strokeWidth"u8); - - if(value != null) + if(sharedStyle.StrokeOpacity.HasValue) { - writer.WriteNumberValue((float)value); + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); } else { writer.WriteNullValue(); } - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("strokeWidth"u8); - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + if(sharedStyle.StrokeWidth.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); } else { writer.WriteNullValue(); } - break; - case "usedcolor": - var allowedVersionsForUsedColor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUsedColor.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("usedColor"u8); - if(value is IEnumerable objectListUsedColor) + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) { - foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStringValue(usedColorItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SharedStyle sharedStyle) - { - throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -651,6 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -659,6 +259,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); if(sharedStyle.FillColor.HasValue) @@ -790,6 +391,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -798,9 +401,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sharedStyle.Actor.HasValue) + { + writer.WriteStringValue(sharedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -811,6 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -819,6 +435,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("fillColor"u8); if(sharedStyle.FillColor.HasValue) @@ -902,244 +519,516 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if(sharedStyle.FontUnderline.HasValue) { - writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(sharedStyle.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(sharedStyle.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(sharedStyle.RevisionNumber); - writer.WritePropertyName("strokeColor"u8); + break; + case "fillopacity": + if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeColor.HasValue) + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) { - writer.WriteStringValue(sharedStyle.StrokeColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeOpacity"u8); + break; + case "fontbold": + if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeOpacity.HasValue) + writer.WritePropertyName("fontBold"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeWidth"u8); + break; + case "fontcolor": + if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeWidth.HasValue) + writer.WritePropertyName("fontColor"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(sharedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + break; + case "fontitalic": + if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) { - writer.WriteStringValue(usedColorItem); + return; } - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SharedStyle for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(sharedStyle.Actor.HasValue) + writer.WritePropertyName("fontItalic"u8); + + if(value != null) { - writer.WriteStringValue(sharedStyle.Actor.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "fontname": + if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("fontName"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("fillColor"u8); + break; + case "fontsize": + if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FillColor.HasValue) + writer.WritePropertyName("fontSize"u8); + + if(value != null) { - writer.WriteStringValue(sharedStyle.FillColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fillOpacity"u8); + break; + case "fontstrokethrough": + if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FillOpacity.HasValue) + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontBold"u8); + break; + case "fontunderline": + if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontBold.HasValue) + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) { - writer.WriteBooleanValue(sharedStyle.FontBold.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontColor"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontColor.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(sharedStyle.FontColor.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontItalic"u8); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontItalic.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontName"u8); - writer.WriteStringValue(sharedStyle.FontName); - writer.WritePropertyName("fontSize"u8); + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontSize.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.FontSize.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontStrokeThrough"u8); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontStrokeThrough.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("fontUnderline"u8); + break; + case "strokecolor": + if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.FontUnderline.HasValue) + writer.WritePropertyName("strokeColor"u8); + + if(value != null) { - writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(sharedStyle.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(sharedStyle.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(sharedStyle.RevisionNumber); - writer.WritePropertyName("strokeColor"u8); + break; + case "strokeopacity": + if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeColor.HasValue) + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) { - writer.WriteStringValue(sharedStyle.StrokeColor.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeOpacity"u8); + break; + case "strokewidth": + if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeOpacity.HasValue) + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + writer.WriteNumberValue((float)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("strokeWidth"u8); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } - if(sharedStyle.StrokeWidth.HasValue) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(sharedStyle.ThingPreference); + break; + case "usedcolor": + if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUsedColor) { - writer.WriteStringValue(usedColorItem); + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index f8aae430a..4abe7173d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,205 @@ namespace CDP4JsonSerializer /// public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not SimpleParameterValue simpleParameterValue) + { + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleParameterValue.Actor.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +256,7 @@ public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSeriali /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +264,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +282,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +300,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +336,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +354,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +372,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { return; } @@ -239,15 +390,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -265,15 +408,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { return; } @@ -291,13 +426,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -315,15 +444,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -336,197 +457,22 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not SimpleParameterValue simpleParameterValue) - { - throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleParameterValue.Iid); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(simpleParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(simpleParameterValue.Scale.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(simpleParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(simpleParameterValue.Scale.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(simpleParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(simpleParameterValue.Scale.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(simpleParameterValue.ThingPreference); - writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(simpleParameterValue.Actor.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleParameterValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("parameterType"u8); - writer.WriteStringValue(simpleParameterValue.ParameterType); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleParameterValue.RevisionNumber); - writer.WritePropertyName("scale"u8); - - if(simpleParameterValue.Scale.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Scale.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(simpleParameterValue.ThingPreference); - writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index d1564944c..0381206b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,401 @@ namespace CDP4JsonSerializer public class SimpleQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not SimpleQuantityKind simpleQuantityKind) + { + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(value is IEnumerable objectListAlias) + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(possibleScaleItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "defaultscale": - var allowedVersionsForDefaultScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("defaultScale"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListDefinition) + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleScaleItem); } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(simpleQuantityKind.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(simpleQuantityKind.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForName.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +453,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "possiblescale": - var allowedVersionsForPossibleScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("possibleScale"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListPossibleScale) + if(value is IEnumerable objectListAlias) { - foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(possibleScaleItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "quantitydimensionsymbol": - var allowedVersionsForQuantityDimensionSymbol = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,25 +507,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("defaultScale"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -472,51 +525,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue((string)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); break; - case "symbol": - var allowedVersionsForSymbol = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -524,23 +615,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -548,355 +633,180 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleQuantityKind"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SimpleQuantityKind simpleQuantityKind) - { - throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(possibleScaleItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(simpleQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(simpleQuantityKind.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(simpleQuantityKind.Name); writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPossibleScale) { - writer.WriteStringValue(possibleScaleItem); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(simpleQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(simpleQuantityKind.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(simpleQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(simpleQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(simpleQuantityKind.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(simpleQuantityKind.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(simpleQuantityKind.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(possibleScaleItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(simpleQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(simpleQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(simpleQuantityKind.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleQuantityKind"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 37ce4c2b7..95afddc3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,424 +51,112 @@ namespace CDP4JsonSerializer public class SimpleUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not SimpleUnit simpleUnit) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); writer.WritePropertyName("isDeprecated"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WriteBooleanValue(simpleUnit.IsDeprecated); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(simpleUnit.Name); writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleUnit"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SimpleUnit simpleUnit) - { - throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(excludedDomainItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -476,10 +165,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleUnit.Name); writer.WritePropertyName("revisionNumber"u8); @@ -487,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(simpleUnit.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +189,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -507,6 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -515,6 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -523,6 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -531,6 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -543,9 +240,22 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(simpleUnit.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleUnit.Actor.HasValue) + { + writer.WriteStringValue(simpleUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -554,6 +264,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -564,6 +275,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -572,6 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -580,6 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -588,6 +302,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -603,82 +318,304 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(simpleUnit.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SimpleUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(simpleUnit.Actor.HasValue) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(simpleUnit.Actor.Value); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(aliasItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(simpleUnit.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(simpleUnit.IsDeprecated); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("name"u8); - writer.WriteStringValue(simpleUnit.Name); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(simpleUnit.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(simpleUnit.ShortName); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(simpleUnit.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleUnit"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 91fb72ddb..727c19091 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,224 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataAnnotation.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataAnnotation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +275,7 @@ public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThing /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - var allowedVersionsForDiscussion = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDiscussion.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) { return; } @@ -211,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -236,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -261,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -311,14 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -336,14 +481,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - var allowedVersionsForPrimaryAnnotatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPrimaryAnnotatedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) { return; } @@ -361,14 +499,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - var allowedVersionsForRelatedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRelatedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) { return; } @@ -386,14 +517,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -411,13 +535,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -440,210 +558,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) - { - throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryDataAnnotation.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryDataAnnotation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("primaryAnnotatedThing"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index b04f9b5d1..227f64e26 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,197 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +248,7 @@ public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IT /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +256,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +274,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +292,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +346,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +364,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +382,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -261,14 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -286,14 +418,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +436,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "replyto": - var allowedVersionsForReplyTo = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReplyTo.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) { return; } @@ -336,14 +454,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,13 +472,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -390,189 +495,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) - { - throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryDataDiscussionItem.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("replyTo"u8); - - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) - { - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 0b02b53b6..64dd01191 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,691 +51,499 @@ namespace CDP4JsonSerializer public class SiteDirectorySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not SiteDirectory siteDirectory) + { + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); - writer.WritePropertyName("actor"u8); - - if(value != null) + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } else { writer.WriteNullValue(); } - break; - case "annotation": - var allowedVersionsForAnnotation = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("defaultPersonRole"u8); - if(!allowedVersionsForAnnotation.Contains(requestedVersion)) + if(siteDirectory.DefaultPersonRole.HasValue) { - return; + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("annotation"u8); + writer.WriteStartArray("domain"u8); - if(value is IEnumerable objectListAnnotation) + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) { - foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(annotationItem); - } + writer.WriteStringValue(domainItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("domainGroup"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainGroupItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(logEntryItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(modelItem); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(naturalLanguageItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(organizationItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(participantRoleItem); } - break; - case "defaultparticipantrole": - var allowedVersionsForDefaultParticipantRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); - if(!allowedVersionsForDefaultParticipantRole.Contains(requestedVersion)) + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(personItem); } - writer.WritePropertyName("defaultParticipantRole"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(personRoleItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(siteReferenceDataLibraryItem); } + writer.WriteEndArray(); + break; - case "defaultpersonrole": - var allowedVersionsForDefaultPersonRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); + writer.WriteStartArray("annotation"u8); - if(!allowedVersionsForDefaultPersonRole.Contains(requestedVersion)) + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(annotationItem); } - writer.WritePropertyName("defaultPersonRole"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } else { writer.WriteNullValue(); } - break; - case "domain": - var allowedVersionsForDomain = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("defaultPersonRole"u8); - if(!allowedVersionsForDomain.Contains(requestedVersion)) + if(siteDirectory.DefaultPersonRole.HasValue) { - return; + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); } writer.WriteStartArray("domain"u8); - if(value is IEnumerable objectListDomain) + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) { - foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + writer.WriteStringValue(domainItem); } - + writer.WriteEndArray(); - break; - case "domaingroup": - var allowedVersionsForDomainGroup = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("domainGroup"u8); - if(!allowedVersionsForDomainGroup.Contains(requestedVersion)) + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainGroupItem); } - writer.WriteStartArray("domainGroup"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListDomainGroup) + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainGroupItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(logEntryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("model"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(modelItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(naturalLanguageItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("organization"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(organizationItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "lastmodifiedon": - var allowedVersionsForLastModifiedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("participantRole"u8); - if(!allowedVersionsForLastModifiedOn.Contains(requestedVersion)) + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(participantRoleItem); } - writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "logentry": - var allowedVersionsForLogEntry = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("person"u8); - if(!allowedVersionsForLogEntry.Contains(requestedVersion)) + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(personItem); } - writer.WriteStartArray("logEntry"u8); - - if(value is IEnumerable objectListLogEntry) - { - foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } - } - writer.WriteEndArray(); - break; - case "model": - var allowedVersionsForModel = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("personRole"u8); - if(!allowedVersionsForModel.Contains(requestedVersion)) + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(personRoleItem); } - writer.WriteStartArray("model"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); - if(value is IEnumerable objectListModel) + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) { - foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modelItem); - } + writer.WriteStringValue(siteReferenceDataLibraryItem); } - + writer.WriteEndArray(); + break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); + writer.WriteStartArray("annotation"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(annotationItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } else { writer.WriteNullValue(); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } + writer.WritePropertyName("defaultPersonRole"u8); - writer.WritePropertyName("name"u8); - - if(value != null) + if(siteDirectory.DefaultPersonRole.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); } else { writer.WriteNullValue(); } - break; - case "naturallanguage": - var allowedVersionsForNaturalLanguage = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("domain"u8); - if(!allowedVersionsForNaturalLanguage.Contains(requestedVersion)) + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(domainItem); } - writer.WriteStartArray("naturalLanguage"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); - if(value is IEnumerable objectListNaturalLanguage) + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) { - foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(naturalLanguageItem); - } + writer.WriteStringValue(domainGroupItem); } - + writer.WriteEndArray(); - break; - case "organization": - var allowedVersionsForOrganization = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForOrganization.Contains(requestedVersion)) + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("organization"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListOrganization) + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "participantrole": - var allowedVersionsForParticipantRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - if(!allowedVersionsForParticipantRole.Contains(requestedVersion)) + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(logEntryItem); } - writer.WriteStartArray("participantRole"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); - if(value is IEnumerable objectListParticipantRole) + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) { - foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantRoleItem); - } + writer.WriteStringValue(modelItem); } - + writer.WriteEndArray(); - break; - case "person": - var allowedVersionsForPerson = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - if(!allowedVersionsForPerson.Contains(requestedVersion)) + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(naturalLanguageItem); } - writer.WriteStartArray("person"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); - if(value is IEnumerable objectListPerson) + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) { - foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personItem); - } + writer.WriteStringValue(organizationItem); } - + writer.WriteEndArray(); - break; - case "personrole": - var allowedVersionsForPersonRole = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("participantRole"u8); - if(!allowedVersionsForPersonRole.Contains(requestedVersion)) + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(participantRoleItem); } - writer.WriteStartArray("personRole"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); - if(value is IEnumerable objectListPersonRole) + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) { - foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } + writer.WriteStringValue(personItem); } - + writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("personRole"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(personRoleItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(siteReferenceDataLibraryItem); } - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectory.Actor.HasValue) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(siteDirectory.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "sitereferencedatalibrary": - var allowedVersionsForSiteReferenceDataLibrary = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("annotation"u8); - if(!allowedVersionsForSiteReferenceDataLibrary.Contains(requestedVersion)) + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(annotationItem); } - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - if(value is IEnumerable objectListSiteReferenceDataLibrary) - { - foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } - } - writer.WriteEndArray(); - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectory"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SiteDirectory siteDirectory) - { - throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); @@ -769,6 +578,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) @@ -777,6 +587,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); @@ -789,6 +618,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("model"u8); foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) @@ -797,6 +627,9 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); writer.WriteStartArray("naturalLanguage"u8); @@ -807,6 +640,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) @@ -815,6 +649,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) @@ -823,6 +658,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("person"u8); foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) @@ -831,6 +667,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) @@ -839,6 +676,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); @@ -851,463 +689,517 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.1.0"); - writer.WriteStartArray("annotation"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(annotationItem); - } + writer.WriteEndObject(); + } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectory.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("defaultParticipantRole"u8); + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(siteDirectory.DefaultParticipantRole.HasValue) - { - writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); - } - else + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WritePropertyName("defaultPersonRole"u8); - - if(siteDirectory.DefaultPersonRole.HasValue) + writer.WritePropertyName("actor"u8); + + if(value != null) { - writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + break; + case "annotation": + if(!AllowedVersionsPerProperty["annotation"].Contains(requestedVersion)) { - writer.WriteStringValue(domainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("domainGroup"u8); + writer.WriteStartArray("annotation"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAnnotation) { - writer.WriteStringValue(domainGroupItem); + foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("classKind"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((ClassKind)value).ToString()); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectory.Iid); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(logEntryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { - writer.WriteStringValue(modelItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("createdOn"u8); + + if(value != null) { - writer.WriteStringValue(naturalLanguageItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(organizationItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + break; + case "defaultparticipantrole": + if(!AllowedVersionsPerProperty["defaultParticipantRole"].Contains(requestedVersion)) { - writer.WriteStringValue(participantRoleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("defaultParticipantRole"u8); + + if(value != null) { - writer.WriteStringValue(personItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectory.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(siteReferenceDataLibraryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.2.0"); - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + case "defaultpersonrole": + if(!AllowedVersionsPerProperty["defaultPersonRole"].Contains(requestedVersion)) { - writer.WriteStringValue(annotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectory.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("defaultParticipantRole"u8); - - if(siteDirectory.DefaultParticipantRole.HasValue) + writer.WritePropertyName("defaultPersonRole"u8); + + if(value != null) { - writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("defaultPersonRole"u8); - - if(siteDirectory.DefaultPersonRole.HasValue) - { - writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); - } - else + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } writer.WriteStartArray("domain"u8); - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDomain) { - writer.WriteStringValue(domainItem); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } } - + writer.WriteEndArray(); + break; + case "domaingroup": + if(!AllowedVersionsPerProperty["domainGroup"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("domainGroup"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDomainGroup) { - writer.WriteStringValue(domainGroupItem); + foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectory.Iid); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(logEntryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("model"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(modelItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(naturalLanguageItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("organization"u8); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + break; + case "lastmodifiedon": + if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(organizationItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("participantRole"u8); + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + break; + case "logentry": + if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) { - writer.WriteStringValue(participantRoleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("person"u8); + writer.WriteStartArray("logEntry"u8); - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListLogEntry) { - writer.WriteStringValue(personItem); + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + break; + case "model": + if(!AllowedVersionsPerProperty["model"].Contains(requestedVersion)) { - writer.WriteStringValue(personRoleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectory.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); + writer.WriteStartArray("model"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListModel) { - writer.WriteStringValue(siteReferenceDataLibraryItem); + foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectory.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectory for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - if(siteDirectory.Actor.HasValue) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(siteDirectory.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(annotationItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectory.ClassKind.ToString()); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("defaultParticipantRole"u8); - - if(siteDirectory.DefaultParticipantRole.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("defaultPersonRole"u8); + break; + case "naturallanguage": + if(!AllowedVersionsPerProperty["naturalLanguage"].Contains(requestedVersion)) + { + return; + } - if(siteDirectory.DefaultPersonRole.HasValue) + writer.WriteStartArray("naturalLanguage"u8); + + if(value is IEnumerable objectListNaturalLanguage) { - writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } } - else + + writer.WriteEndArray(); + break; + case "organization": + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("domain"u8); + writer.WriteStartArray("organization"u8); - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListOrganization) { - writer.WriteStringValue(domainItem); + foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("domainGroup"u8); - - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + break; + case "participantrole": + if(!AllowedVersionsPerProperty["participantRole"].Contains(requestedVersion)) { - writer.WriteStringValue(domainGroupItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("participantRole"u8); - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListParticipantRole) { - writer.WriteStringValue(excludedDomainItem); + foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "person": + if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectory.Iid); - writer.WritePropertyName("lastModifiedOn"u8); - writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); + writer.WriteStartArray("person"u8); - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPerson) { - writer.WriteStringValue(logEntryItem); + foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + break; + case "personrole": + if(!AllowedVersionsPerProperty["personRole"].Contains(requestedVersion)) { - writer.WriteStringValue(modelItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); + writer.WriteStartArray("personRole"u8); - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPersonRole) { - writer.WriteStringValue(naturalLanguageItem); + foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(organizationItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(participantRoleItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(personItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("personRole"u8); + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + break; + case "sitereferencedatalibrary": + if(!AllowedVersionsPerProperty["siteReferenceDataLibrary"].Contains(requestedVersion)) { - writer.WriteStringValue(personRoleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectory.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(siteDirectory.ShortName); writer.WriteStartArray("siteReferenceDataLibrary"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSiteReferenceDataLibrary) { - writer.WriteStringValue(siteReferenceDataLibraryItem); + foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } } - + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectory.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectory"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "annotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultParticipantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultPersonRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domainGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "model", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "naturalLanguage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "siteReferenceDataLibrary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 22b0c2310..4600c357d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,152 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) + { + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryThingReference.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +203,7 @@ public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThing /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +211,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +229,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -111,14 +247,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -136,14 +265,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -161,14 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -186,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -211,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedrevisionnumber": - var allowedVersionsForReferencedRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencedRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) { return; } @@ -236,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedthing": - var allowedVersionsForReferencedThing = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForReferencedThing.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) { return; } @@ -261,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -286,13 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -315,144 +396,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) - { - throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteDirectoryThingReference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryThingReference.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryThingReference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteDirectoryThingReference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("referencedRevisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); - writer.WritePropertyName("referencedThing"u8); - writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 89790245c..407871d73 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,288 +51,371 @@ namespace CDP4JsonSerializer public class SiteLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List + Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) { - "1.3.0", - }; + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(siteLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "affecteddomainiid": - var allowedVersionsForAffectedDomainIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForAffectedDomainIid.Contains(requestedVersion)) + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("affectedDomainIid"u8); - - if(value is IEnumerable objectListAffectedDomainIid) - { - foreach(var affectedDomainIidItem in objectListAffectedDomainIid) - { - writer.WriteStringValue((Guid)affectedDomainIidItem); - } - } - writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); break; - case "affecteditemiid": - var allowedVersionsForAffectedItemIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); - if(!allowedVersionsForAffectedItemIid.Contains(requestedVersion)) + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) { - return; + writer.WriteStringValue(affectedDomainIidItem); } - writer.WriteStartArray("affectedItemIid"u8); - - if(value is IEnumerable objectListAffectedItemIid) - { - foreach(var affectedItemIidItem in objectListAffectedItemIid) - { - writer.WriteStringValue((Guid)affectedItemIidItem); - } - } - writer.WriteEndArray(); - break; - case "author": - var allowedVersionsForAuthor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("author"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(siteLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListCategory) + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(excludedDomainItem); } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); break; - case "classkind": - var allowedVersionsForClassKind = new List + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) { - return; + writer.WriteStringValue(affectedItemIidItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(siteLogEntry.Author.Value); } else { writer.WriteNullValue(); } - break; - case "content": - var allowedVersionsForContent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForContent.Contains(requestedVersion)) + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("content"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(excludedDomainItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(logEntryChangelogItemItem); } - writer.WritePropertyName("createdOn"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteLogEntry.Actor.HasValue) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(siteLogEntry.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("affectedDomainIid"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) { - return; + writer.WriteStringValue(affectedDomainIidItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(affectedItemIidItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List + + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -343,51 +427,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + case "affecteddomainiid": + if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("languageCode"u8); - - if(value != null) + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) { - writer.WriteStringValue((string)value); + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } } - else + + writer.WriteEndArray(); + break; + case "affecteditemiid": + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "level": - var allowedVersionsForLevel = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("affectedItemIid"u8); - if(!allowedVersionsForLevel.Contains(requestedVersion)) + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("level"u8); + writer.WritePropertyName("author"u8); if(value != null) { - writer.WriteStringValue(((LogLevelKind)value).ToString()); + writer.WriteStringValue((Guid)value); } else { @@ -395,48 +481,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "logentrychangelogitem": - var allowedVersionsForLogEntryChangelogItem = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLogEntryChangelogItem.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("logEntryChangelogItem"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListLogEntryChangelogItem) + if(value is IEnumerable objectListCategory) { - foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(logEntryChangelogItemItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -444,25 +517,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("content"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((string)value); } else { @@ -470,23 +535,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("createdOn"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { @@ -494,335 +553,196 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteLogEntry"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SiteLogEntry siteLogEntry) - { - throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.0.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedDomainIidItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(affectedItemIidItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(siteLogEntry.Author.HasValue) - { - writer.WriteStringValue(siteLogEntry.Author.Value); - } - else + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - writer.WriteStartArray("category"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(categoryItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteLogEntry.RevisionNumber); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.1.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(siteLogEntry.Author.HasValue) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(siteLogEntry.Author.Value); + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("languageCode"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteLogEntry.RevisionNumber); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.2.0"); - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + case "level": + if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(siteLogEntry.Author.HasValue) + writer.WritePropertyName("level"u8); + + if(value != null) { - writer.WriteStringValue(siteLogEntry.Author.Value); + writer.WriteStringValue(((LogLevelKind)value).ToString()); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "logentrychangelogitem": + if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListLogEntryChangelogItem) { - writer.WriteStringValue(excludedPersonItem); + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(logEntryChangelogItemItem); + return; } - writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteLogEntry.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteLogEntry.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteLogEntry for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteLogEntry.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(siteLogEntry.Actor.Value); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } else { writer.WriteNullValue(); } - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(affectedItemIidItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("author"u8); - - if(siteLogEntry.Author.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(siteLogEntry.Author.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(siteLogEntry.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteLogEntry.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(siteLogEntry.LanguageCode); - writer.WritePropertyName("level"u8); - writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(logEntryChangelogItemItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteLogEntry.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteLogEntry.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteLogEntry"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index 138ecdcfc..d4efc9722 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,822 +51,481 @@ namespace CDP4JsonSerializer public class SiteReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteOrderedItem(baseQuantityKindItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(baseUnitItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(constantItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); - if(value is IEnumerable objectListAlias) + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(definedCategoryItem); } - + writer.WriteEndArray(); - break; - case "basequantitykind": - var allowedVersionsForBaseQuantityKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForBaseQuantityKind.Contains(requestedVersion)) + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("baseQuantityKind"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); - if(value is IEnumerable objectListBaseQuantityKind) + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) { - foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(baseQuantityKindItem); - } + writer.WriteStringValue(fileTypeItem); } - + writer.WriteEndArray(); - break; - case "baseunit": - var allowedVersionsForBaseUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("glossary"u8); - if(!allowedVersionsForBaseUnit.Contains(requestedVersion)) + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(glossaryItem); } - writer.WriteStartArray("baseUnit"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListBaseUnit) + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(parameterTypeItem); + } - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceSourceItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } else { writer.WriteNullValue(); } - break; - case "constant": - var allowedVersionsForConstant = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - if(!allowedVersionsForConstant.Contains(requestedVersion)) + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(ruleItem); } - writer.WriteStartArray("constant"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); - if(value is IEnumerable objectListConstant) + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) { - foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + writer.WriteStringValue(scaleItem); } - + writer.WriteEndArray(); - break; - case "definedcategory": - var allowedVersionsForDefinedCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - if(!allowedVersionsForDefinedCategory.Contains(requestedVersion)) + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(unitItem); } - writer.WriteStartArray("definedCategory"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); - if(value is IEnumerable objectListDefinedCategory) + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) { - foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStringValue(unitPrefixItem); } - + writer.WriteEndArray(); + break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); - if(value is IEnumerable objectListDefinition) + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteOrderedItem(baseQuantityKindItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("baseUnit"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(baseUnitItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(constantItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("definedCategory"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definedCategoryItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(definitionItem); } - - writer.WriteEndArray(); - break; - case "filetype": - var allowedVersionsForFileType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - if(!allowedVersionsForFileType.Contains(requestedVersion)) + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("fileType"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListFileType) + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "glossary": - var allowedVersionsForGlossary = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("fileType"u8); - if(!allowedVersionsForGlossary.Contains(requestedVersion)) + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(fileTypeItem); } + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - if(value is IEnumerable objectListGlossary) + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) { - foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStringValue(glossaryItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(parameterTypeItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("referenceSource"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(referenceSourceItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(ruleItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(scaleItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(unitItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(unitPrefixItem); } + writer.WriteEndArray(); + break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "parametertype": - var allowedVersionsForParameterType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("baseQuantityKind"u8); - if(!allowedVersionsForParameterType.Contains(requestedVersion)) + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) { - return; + writer.WriteOrderedItem(baseQuantityKindItem); } - writer.WriteStartArray("parameterType"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); - if(value is IEnumerable objectListParameterType) + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) { - foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStringValue(baseUnitItem); } - + writer.WriteEndArray(); - break; - case "referencesource": - var allowedVersionsForReferenceSource = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - if(!allowedVersionsForReferenceSource.Contains(requestedVersion)) + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(constantItem); } - writer.WriteStartArray("referenceSource"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); - if(value is IEnumerable objectListReferenceSource) + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) { - foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStringValue(definedCategoryItem); } - + writer.WriteEndArray(); - break; - case "requiredrdl": - var allowedVersionsForRequiredRdl = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForRequiredRdl.Contains(requestedVersion)) + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("requiredRdl"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(fileTypeItem); } - break; - case "rule": - var allowedVersionsForRule = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); - if(!allowedVersionsForRule.Contains(requestedVersion)) + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(glossaryItem); } - writer.WriteStartArray("rule"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListRule) + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "scale": - var allowedVersionsForScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForScale.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("scale"u8); - - if(value is IEnumerable objectListScale) - { - foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } - } - - writer.WriteEndArray(); - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("shortName"u8); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("unit"u8); - - if(value is IEnumerable objectListUnit) - { - foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } - } - - writer.WriteEndArray(); - break; - case "unitprefix": - var allowedVersionsForUnitPrefix = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnitPrefix.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("unitPrefix"u8); - - if(value is IEnumerable objectListUnitPrefix) - { - foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } - } - - writer.WriteEndArray(); - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) - { - throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(baseQuantityKindItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); writer.WriteStartArray("parameterType"u8); @@ -876,6 +536,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -884,6 +545,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); if(siteReferenceDataLibrary.RequiredRdl.HasValue) @@ -905,6 +567,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -913,8 +576,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -923,6 +589,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -931,9 +598,21 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -942,6 +621,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -950,6 +630,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -958,6 +639,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); writer.WriteStartArray("constant"u8); @@ -968,6 +650,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -976,6 +659,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -984,6 +668,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -992,6 +677,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -1000,6 +686,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -1008,6 +695,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -1016,6 +704,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -1024,6 +713,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -1040,6 +730,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -1048,6 +739,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); if(siteReferenceDataLibrary.RequiredRdl.HasValue) @@ -1069,6 +761,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -1077,8 +770,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -1087,6 +783,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -1095,356 +792,553 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; } + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + writer.WriteEndArray(); + break; + case "basequantitykind": + if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListBaseQuantityKind) { - writer.WriteOrderedItem(baseQuantityKindItem); + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } } - + writer.WriteEndArray(); + break; + case "baseunit": + if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListBaseUnit) { - writer.WriteStringValue(baseUnitItem); + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + break; + case "constant": + if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) { - writer.WriteStringValue(constantItem); + return; } + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + writer.WriteEndArray(); + break; + case "definedcategory": + if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinedCategory) { - writer.WriteStringValue(definedCategoryItem); + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } } - + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(definitionItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListFileType) { - writer.WriteStringValue(fileTypeItem); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } } - + writer.WriteEndArray(); + break; + case "glossary": + if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListGlossary) { - writer.WriteStringValue(glossaryItem); + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteReferenceDataLibrary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(parameterTypeItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("referenceSource"u8); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(referenceSourceItem); + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("requiredRdl"u8); + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + writer.WriteBooleanValue((bool)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(ruleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(scaleItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(unitItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(unitPrefixItem); + return; } - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteReferenceDataLibrary.Actor.HasValue) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(siteReferenceDataLibrary.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("baseQuantityKind"u8); + writer.WriteStartArray("parameterType"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if(value is IEnumerable objectListParameterType) { - writer.WriteOrderedItem(baseQuantityKindItem); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + break; + case "referencesource": + if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) { - writer.WriteStringValue(baseUnitItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); + writer.WriteStartArray("referenceSource"u8); - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListReferenceSource) { - writer.WriteStringValue(constantItem); + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) { - writer.WriteStringValue(definedCategoryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(fileTypeItem); + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + break; + case "rule": + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) { - writer.WriteStringValue(glossaryItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("rule"u8); - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRule) { - writer.WriteStringValue(hyperLinkItem); + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(siteReferenceDataLibrary.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) { - writer.WriteStringValue(parameterTypeItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("referenceSource"u8); + writer.WriteStartArray("scale"u8); - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListScale) { - writer.WriteStringValue(referenceSourceItem); + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("requiredRdl"u8); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(ruleItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("scale"u8); + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { - writer.WriteStringValue(scaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); writer.WriteStartArray("unit"u8); - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUnit) { - writer.WriteStringValue(unitItem); + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } } - + writer.WriteEndArray(); + break; + case "unitprefix": + if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListUnitPrefix) { - writer.WriteStringValue(unitPrefixItem); + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 96fb334f7..4bfe39b12 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,170 @@ namespace CDP4JsonSerializer /// public class SolutionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not Solution solution) + { + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(solution.Actor.HasValue) + { + writer.WriteStringValue(solution.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +221,7 @@ public class SolutionSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +229,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +247,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "author": - var allowedVersionsForAuthor = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAuthor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) { return; } @@ -111,14 +265,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +301,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -261,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -286,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -336,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,13 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -390,162 +468,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not Solution solution) - { - throw new ArgumentException("The thing shall be a Solution", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.1.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(solution.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(solution.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(solution.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(solution.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(solution.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(solution.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(solution.RevisionNumber); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.2.0"); - writer.WritePropertyName("author"u8); - writer.WriteStringValue(solution.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(solution.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(solution.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(solution.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(solution.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(solution.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(solution.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(solution.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Solution for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(solution.Actor.HasValue) - { - writer.WriteStringValue(solution.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("author"u8); - writer.WriteStringValue(solution.Author); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(solution.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(solution.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(solution.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(solution.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(solution.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(solution.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(solution.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index 411b0211e..eac937655 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,409 @@ namespace CDP4JsonSerializer public class SpecializedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(categoryItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(definitionItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(value is IEnumerable objectListAlias) + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(possibleScaleItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "defaultscale": - var allowedVersionsForDefaultScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefaultScale.Contains(requestedVersion)) + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("defaultScale"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(possibleScaleItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListDefinition) + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedPersonItem); } - + writer.WriteEndArray(); - break; - case "general": - var allowedVersionsForGeneral = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForGeneral.Contains(requestedVersion)) + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("general"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(specializedQuantityKind.Actor.HasValue) { - return; + writer.WriteStringValue(specializedQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteBooleanValue((bool)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue((Guid)value); } else { @@ -394,77 +461,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "possiblescale": - var allowedVersionsForPossibleScale = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForPossibleScale.Contains(requestedVersion)) + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("possibleScale"u8); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListPossibleScale) + if(value is IEnumerable objectListCategory) { - foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(possibleScaleItem); + writer.WriteStringValue(categoryItem); } } writer.WriteEndArray(); break; - case "quantitydimensionsymbol": - var allowedVersionsForQuantityDimensionSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForQuantityDimensionSymbol.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -472,25 +515,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("defaultScale"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -498,51 +533,71 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); break; - case "symbol": - var allowedVersionsForSymbol = new List + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "general": + if(!AllowedVersionsPerProperty["general"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("general"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -550,23 +605,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -574,363 +641,199 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the SpecializedQuantityKind"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not SpecializedQuantityKind specializedQuantityKind) - { - throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("general"u8); - writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(specializedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(specializedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(specializedQuantityKind.Symbol); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(categoryItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("general"u8); - writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(specializedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(specializedQuantityKind.Name); writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListPossibleScale) { - writer.WriteStringValue(possibleScaleItem); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(specializedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(specializedQuantityKind.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("general"u8); - writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(specializedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(possibleScaleItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(specializedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(specializedQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(specializedQuantityKind.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing SpecializedQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(specializedQuantityKind.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(specializedQuantityKind.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); - writer.WritePropertyName("defaultScale"u8); - writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedPersonItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("general"u8); - writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(hyperLinkItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(specializedQuantityKind.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(possibleScaleItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("quantityDimensionSymbol"u8); - writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(specializedQuantityKind.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(specializedQuantityKind.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(specializedQuantityKind.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the SpecializedQuantityKind"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "general", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 336a62045..140d52943 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,522 +51,273 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not StakeHolderValueMap stakeHolderValueMap) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("goal"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(goalItem); } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "goal": - var allowedVersionsForGoal = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForGoal.Contains(requestedVersion)) + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("goal"u8); - - if(value is IEnumerable objectListGoal) - { - foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(requirementItem); } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(settingsItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderValueItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("valueGroup"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(valueGroupItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - break; - case "requirement": - var allowedVersionsForRequirement = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForRequirement.Contains(requestedVersion)) + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("requirement"u8); - - if(value is IEnumerable objectListRequirement) - { - foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } - } - writer.WriteEndArray(); - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "settings": - var allowedVersionsForSettings = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForSettings.Contains(requestedVersion)) + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("settings"u8); - - if(value is IEnumerable objectListSettings) - { - foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(settingsItem); - } - } - writer.WriteEndArray(); - break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "stakeholdervalue": - var allowedVersionsForStakeholderValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("stakeholderValue"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); - if(value is IEnumerable objectListStakeholderValue) + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) { - foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStringValue(goalItem); } - + writer.WriteEndArray(); - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(requirementItem); } - break; - case "valuegroup": - var allowedVersionsForValueGroup = new List + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - if(!allowedVersionsForValueGroup.Contains(requestedVersion)) + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderValueItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); writer.WriteStartArray("valueGroup"u8); - if(value is IEnumerable objectListValueGroup) + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) { - foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStringValue(valueGroupItem); } - + writer.WriteEndArray(); + break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not StakeHolderValueMap stakeHolderValueMap) - { - throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WriteStartObject(); + if(stakeHolderValueMap.Actor.HasValue) + { + writer.WriteStringValue(stakeHolderValueMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.1.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) @@ -574,6 +326,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) @@ -582,6 +335,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -592,6 +346,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -600,6 +355,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -608,6 +364,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) @@ -616,6 +373,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -624,6 +382,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); writer.WritePropertyName("modifiedOn"u8); @@ -638,6 +397,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); writer.WriteStartArray("settings"u8); @@ -648,252 +408,423 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(stakeholderValueItem); + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goal": + if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("goal"u8); + + if(value is IEnumerable objectListGoal) + { + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; } - writer.WriteEndArray(); - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(valueGroupItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(goalItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeHolderValueMap.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeHolderValueMap.Name); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(requirementItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - writer.WriteStartArray("settings"u8); - - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(settingsItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeHolderValueMap.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + break; + case "requirement": + if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderValueItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeHolderValueMap.ThingPreference); - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("requirement"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListRequirement) { - writer.WriteStringValue(valueGroupItem); + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } } - + writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMap for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(stakeHolderValueMap.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(stakeHolderValueMap.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "settings": + if(!AllowedVersionsPerProperty["settings"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("settings"u8); - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListSettings) { - writer.WriteStringValue(categoryItem); + foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) { - writer.WriteStringValue(goalItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("stakeholderValue"u8); - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListStakeholderValue) { - writer.WriteStringValue(hyperLinkItem); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeHolderValueMap.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeHolderValueMap.Name); - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(requirementItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - writer.WriteStartArray("settings"u8); - - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(settingsItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeHolderValueMap.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + break; + case "valuegroup": + if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) { - writer.WriteStringValue(stakeholderValueItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeHolderValueMap.ThingPreference); writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListValueGroup) { - writer.WriteStringValue(valueGroupItem); + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } } - + writer.WriteEndArray(); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "settings", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 5d4612705..9a0ecc249 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,296 +50,6 @@ namespace CDP4JsonSerializer /// public class StakeHolderValueMapSettingsSerializer : BaseThingSerializer, IThingSerializer { - /// - /// Serialize a value for a property into a - /// - /// The name of the property to serialize - /// The object value to serialize - /// The - /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) - { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("classKind"u8); - - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - - writer.WriteEndArray(); - break; - case "goaltovaluegrouprelationship": - var allowedVersionsForGoalToValueGroupRelationship = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForGoalToValueGroupRelationship.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("goalToValueGroupRelationship"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("iid"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "stakeholdervaluetorequirementrelationship": - var allowedVersionsForStakeholderValueToRequirementRelationship = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStakeholderValueToRequirementRelationship.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("thingPreference"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "valuegrouptostakeholdervaluerelationship": - var allowedVersionsForValueGroupToStakeholderValueRelationship = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValueGroupToStakeholderValueRelationship.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMapSettings"); - } - } - /// /// Serializes a into an /// @@ -365,7 +76,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM switch(requestedDataModelVersion.ToString(3)) { case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -376,6 +87,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -384,6 +96,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) @@ -425,7 +138,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); writer.WriteStartArray("excludedDomain"u8); @@ -436,6 +149,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -444,6 +158,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) @@ -487,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); writer.WritePropertyName("actor"u8); if(stakeHolderValueMapSettings.Actor.HasValue) @@ -509,6 +224,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -517,6 +233,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("goalToValueGroupRelationship"u8); if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) @@ -565,6 +282,241 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goaltovaluegrouprelationship": + if(!AllowedVersionsPerProperty["goalToValueGroupRelationship"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervaluetorequirementrelationship": + if(!AllowedVersionsPerProperty["stakeholderValueToRequirementRelationship"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegrouptostakeholdervaluerelationship": + if(!AllowedVersionsPerProperty["valueGroupToStakeholderValueRelationship"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMapSettings"); + } + } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goalToValueGroupRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueToRequirementRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroupToStakeholderValueRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index fcde18fc7..4e34a4882 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,334 +51,311 @@ namespace CDP4JsonSerializer public class StakeholderSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not Stakeholder stakeholder) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(categoryItem); } - writer.WriteStartArray("category"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListCategory) + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedPersonItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - if(value is IEnumerable objectListDefinition) + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(stakeholderValueItem); } - + writer.WriteEndArray(); + break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(stakeholderValueItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholder.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(stakeholder.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("revisionNumber"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue(hyperLinkItem); } - else + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(stakeholderValueItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(!allowedVersionsForShortName.Contains(requestedVersion)) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -385,48 +363,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "stakeholdervalue": - var allowedVersionsForStakeholderValue = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStakeholderValue.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WriteStartArray("stakeholderValue"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListStakeholderValue) + if(value is IEnumerable objectListAlias) { - foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(stakeholderValueItem); + writer.WriteStringValue(aliasItem); } } writer.WriteEndArray(); break; - case "thingpreference": - var allowedVersionsForThingPreference = new List + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("category"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -434,270 +417,230 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Stakeholder"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Stakeholder stakeholder) - { - throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); + writer.WriteStartArray("definition"u8); - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue(categoryItem); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholder.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholder.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(stakeholderValueItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholder.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholder.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + + if(value != null) { - writer.WriteStringValue(stakeholderValueItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeholder.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Stakeholder for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(stakeholder.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(stakeholder.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("stakeholderValue"u8); - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListStakeholderValue) { - writer.WriteStringValue(excludedPersonItem); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholder.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholder.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholder.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(stakeholderValueItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeholder.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Stakeholder"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 7a7afb846..5279e8a3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,260 @@ namespace CDP4JsonSerializer /// public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholderValue.Actor.HasValue) + { + writer.WriteStringValue(stakeholderValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +311,7 @@ public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "alias": - var allowedVersionsForAlias = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } @@ -111,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -136,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -161,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - var allowedVersionsForDefinition = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } @@ -186,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } @@ -261,14 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +481,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +499,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -336,14 +517,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,14 +535,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +553,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,240 +576,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not StakeholderValue stakeholderValue) - { - throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholderValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholderValue.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholderValue.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholderValue.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholderValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholderValue.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholderValue.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholderValue.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeholderValue.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing StakeholderValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(stakeholderValue.Actor.HasValue) - { - writer.WriteStringValue(stakeholderValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(stakeholderValue.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(stakeholderValue.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(stakeholderValue.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(stakeholderValue.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(stakeholderValue.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index 028bdf061..edd1133a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,193 @@ namespace CDP4JsonSerializer /// public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(telephoneNumber.Actor.HasValue) + { + writer.WriteStringValue(telephoneNumber.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +244,7 @@ public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +252,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +270,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +306,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +324,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +342,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +360,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,13 +378,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -263,15 +396,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -289,15 +414,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "vcardtype": - var allowedVersionsForVcardType = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForVcardType.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) { return; } @@ -320,181 +437,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not TelephoneNumber telephoneNumber) - { - throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(telephoneNumber.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(telephoneNumber.RevisionNumber); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(telephoneNumber.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(telephoneNumber.RevisionNumber); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(telephoneNumber.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(telephoneNumber.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(telephoneNumber.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing TelephoneNumber for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(telephoneNumber.Actor.HasValue) - { - writer.WriteStringValue(telephoneNumber.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(telephoneNumber.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(telephoneNumber.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(telephoneNumber.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 14e1340b2..00c4ad377 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,424 +51,112 @@ namespace CDP4JsonSerializer public class TermSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); - - switch(propertyName.ToLower()) + if (thing is not Term term) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); + return; + } - if(!allowedVersionsForAlias.Contains(requestedVersion)) - { - return; - } + writer.WriteStartObject(); + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListAlias) - { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - } - - writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else - { - writer.WriteNullValue(); - } - - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListDefinition) - { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - } - - writer.WriteEndArray(); - break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) - { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - } - writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) - { - return; - } - - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) - { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - } - writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) - { - return; - } - writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) - { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - } - - writer.WriteEndArray(); - break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(hyperLinkItem); } - writer.WritePropertyName("iid"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) - { - return; - } - + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); writer.WritePropertyName("isDeprecated"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("modifiedOn"u8); - - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) - { - return; - } - + writer.WriteBooleanValue(term.IsDeprecated); writer.WritePropertyName("name"u8); - - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) - { - return; - } - + writer.WriteStringValue(term.Name); writer.WritePropertyName("revisionNumber"u8); - - if(value != null) - { - writer.WriteNumberValue((int)value); - } - else - { - writer.WriteNullValue(); - } - + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("shortName"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("thingPreference"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else - { - writer.WriteNullValue(); - } - - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the Term"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not Term term) - { - throw new ArgumentException("The thing shall be a Term", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(aliasItem); + writer.WriteStringValue(excludedDomainItem); } writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(excludedPersonItem); } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -476,10 +165,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); writer.WritePropertyName("isDeprecated"u8); writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(term.Name); writer.WritePropertyName("revisionNumber"u8); @@ -487,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(term.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.1.0"); + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -497,6 +189,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -507,6 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -515,6 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -523,6 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -531,6 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -543,9 +240,22 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(term.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.2.0"); + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(term.Actor.HasValue) + { + writer.WriteStringValue(term.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -554,6 +264,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); writer.WriteStartArray("definition"u8); @@ -564,6 +275,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -572,6 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -580,6 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -588,6 +302,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); writer.WritePropertyName("isDeprecated"u8); @@ -603,82 +318,304 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(term.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing Term for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } - if(term.Actor.HasValue) + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { - writer.WriteStringValue(term.Actor.Value); + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); } else { writer.WriteNullValue(); } + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("alias"u8); - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue(aliasItem); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(excludedDomainItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(excludedPersonItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("iid"u8); - writer.WriteStringValue(term.Iid); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(term.IsDeprecated); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("name"u8); - writer.WriteStringValue(term.Name); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(term.RevisionNumber); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(term.ShortName); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(term.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the Term"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index 9c1d07169..daafd885e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,349 @@ namespace CDP4JsonSerializer public class TextParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not TextParameterType textParameterType) + { + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(textParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(textParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the TextParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not TextParameterType textParameterType) - { - throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(textParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(textParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(textParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(textParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(textParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(textParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(textParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing TextParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(textParameterType.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(textParameterType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(textParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(textParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(textParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index 168f24037..132af6d3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,203 @@ namespace CDP4JsonSerializer /// public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not TextualNote textualNote) + { + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(textualNote.Actor.HasValue) + { + writer.WriteStringValue(textualNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +254,7 @@ public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +262,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +280,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -111,14 +298,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -136,14 +316,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - var allowedVersionsForContent = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForContent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) { return; } @@ -161,14 +334,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - var allowedVersionsForCreatedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCreatedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) { return; } @@ -186,14 +352,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +370,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -261,14 +406,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - var allowedVersionsForLanguageCode = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForLanguageCode.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) { return; } @@ -286,14 +424,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +442,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -336,14 +460,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - var allowedVersionsForOwner = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForOwner.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) { return; } @@ -361,14 +478,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -386,14 +496,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -411,13 +514,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -440,192 +537,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not TextualNote textualNote) - { - throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.1.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textualNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(textualNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textualNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(textualNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textualNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(textualNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textualNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textualNote.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.2.0"); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textualNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(textualNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textualNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(textualNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textualNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(textualNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textualNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textualNote.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(textualNote.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing TextualNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(textualNote.Actor.HasValue) - { - writer.WriteStringValue(textualNote.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(textualNote.ClassKind.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(textualNote.Content); - writer.WritePropertyName("createdOn"u8); - writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(textualNote.Iid); - writer.WritePropertyName("languageCode"u8); - writer.WriteStringValue(textualNote.LanguageCode); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(textualNote.Name); - writer.WritePropertyName("owner"u8); - writer.WriteStringValue(textualNote.Owner); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(textualNote.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(textualNote.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(textualNote.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index a2f051dc4..aca7ec451 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,343 +51,349 @@ namespace CDP4JsonSerializer public class TimeOfDayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not TimeOfDayParameterType timeOfDayParameterType) + { + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListAlias) + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); break; - case "category": - var allowedVersionsForCategory = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForCategory.Contains(requestedVersion)) + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListCategory) + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((ClassKind)value).ToString()); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(categoryItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) - { - return; - } + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - writer.WritePropertyName("iid"u8); - - if(value != null) + if(timeOfDayParameterType.Actor.HasValue) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(timeOfDayParameterType.Actor.Value); } else { writer.WriteNullValue(); } - break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("isDeprecated"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WritePropertyName("modifiedOn"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); - } - else + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForName.Contains(requestedVersion)) + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WritePropertyName("name"u8); + writer.WriteEndArray(); - if(value != null) - { - writer.WriteStringValue((string)value); - } - else + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); + + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); + writer.WritePropertyName("actor"u8); if(value != null) { - writer.WriteNumberValue((int)value); + writer.WriteStringValue((Guid)value); } else { @@ -394,51 +401,53 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); - - if(value != null) + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteStringValue((string)value); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - else + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - case "symbol": - var allowedVersionsForSymbol = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteStartArray("category"u8); - if(!allowedVersionsForSymbol.Contains(requestedVersion)) + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("symbol"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -446,331 +455,249 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); - - if(value != null) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) { - writer.WriteStringValue((string)value); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } - break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the TimeOfDayParameterType"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not TimeOfDayParameterType timeOfDayParameterType) - { - throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteStringValue(aliasItem); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - + writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteStringValue(categoryItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListExcludedPerson) { - writer.WriteStringValue(definitionItem); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } } - + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if(value is IEnumerable objectListHyperLink) { - writer.WriteStringValue(hyperLinkItem); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } } - + writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(timeOfDayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(timeOfDayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(timeOfDayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(timeOfDayParameterType.Symbol); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("iid"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((Guid)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteBooleanValue((bool)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(timeOfDayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(timeOfDayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(timeOfDayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(timeOfDayParameterType.Symbol); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(timeOfDayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(timeOfDayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(timeOfDayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(timeOfDayParameterType.Symbol); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(timeOfDayParameterType.ThingPreference); break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing TimeOfDayParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } - if(timeOfDayParameterType.Actor.HasValue) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(timeOfDayParameterType.Actor.Value); + writer.WriteNumberValue((int)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("shortName"u8); + + if(value != null) { - writer.WriteStringValue(categoryItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(definitionItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("symbol"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(timeOfDayParameterType.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(timeOfDayParameterType.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(timeOfDayParameterType.ShortName); - writer.WritePropertyName("symbol"u8); - writer.WriteStringValue(timeOfDayParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the TimeOfDayParameterType"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 5e5c72687..5e29c196b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not UnitFactor unitFactor) + { + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(unitFactor.Actor.HasValue) + { + writer.WriteStringValue(unitFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "exponent": - var allowedVersionsForExponent = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExponent.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) { return; } @@ -188,15 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,14 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -239,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -265,13 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -289,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - var allowedVersionsForUnit = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForUnit.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not UnitFactor unitFactor) - { - throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(unitFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitFactor.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitFactor.RevisionNumber); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(unitFactor.Unit); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(unitFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitFactor.RevisionNumber); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(unitFactor.Unit); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(unitFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitFactor.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(unitFactor.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(unitFactor.Unit); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing UnitFactor for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(unitFactor.Actor.HasValue) - { - writer.WriteStringValue(unitFactor.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("exponent"u8); - writer.WriteStringValue(unitFactor.Exponent); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitFactor.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitFactor.RevisionNumber); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(unitFactor.ThingPreference); - writer.WritePropertyName("unit"u8); - writer.WriteStringValue(unitFactor.Unit); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index dfbf4c97d..9bed99333 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -50,236 +51,309 @@ namespace CDP4JsonSerializer public class UnitPrefixSerializer : BaseThingSerializer, IThingSerializer { /// - /// Serialize a value for a property into a + /// Serializes a into an /// - /// The name of the property to serialize - /// The object value to serialize + /// The that have to be serialized /// The /// The that has been requested for the serialization - public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var requestedVersion = requestedDataModelVersion.ToString(3); + if (thing is not UnitPrefix unitPrefix) + { + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); + } - switch(propertyName.ToLower()) + if (requestedDataModelVersion < Version.Parse("1.0.0")) { - case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; + Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForActor.Contains(requestedVersion)) + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("actor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((Guid)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); break; - case "alias": - var allowedVersionsForAlias = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForAlias.Contains(requestedVersion)) + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WriteStartArray("alias"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - if(value is IEnumerable objectListAlias) + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) { - foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + writer.WriteStringValue(definitionItem); } - + writer.WriteEndArray(); - break; - case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedDomain"u8); - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedDomainItem); } - writer.WritePropertyName("classKind"u8); + writer.WriteEndArray(); - if(value != null) + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(((ClassKind)value).ToString()); + writer.WriteStringValue(excludedPersonItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); break; - case "conversionfactor": - var allowedVersionsForConversionFactor = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - if(!allowedVersionsForConversionFactor.Contains(requestedVersion)) + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(aliasItem); } - writer.WritePropertyName("conversionFactor"u8); + writer.WriteEndArray(); - if(value != null) + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue((string)value); + writer.WriteStringValue(definitionItem); } - else + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(excludedDomainItem); } - break; - case "definition": - var allowedVersionsForDefinition = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } - writer.WriteStartArray("definition"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListDefinition) + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); break; - case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.3.0"); + writer.WritePropertyName("actor"u8); - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(unitPrefix.Actor.HasValue) { - return; + writer.WriteStringValue(unitPrefix.Actor.Value); + } + else + { + writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("alias"u8); - if(value is IEnumerable objectListExcludedDomain) + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStringValue(aliasItem); } - + writer.WriteEndArray(); - break; - case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(definitionItem); } - writer.WriteStartArray("excludedPerson"u8); + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - if(value is IEnumerable objectListExcludedPerson) + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) { - foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStringValue(excludedDomainItem); } - + writer.WriteEndArray(); - break; - case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + + writer.WriteStartArray("excludedPerson"u8); - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) { - return; + writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - if(value is IEnumerable objectListHyperLink) + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) { - foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStringValue(hyperLinkItem); } - + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); break; - case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + var requestedVersion = requestedDataModelVersion.ToString(3); - if(!allowedVersionsForIid.Contains(requestedVersion)) + switch(propertyName.ToLower()) + { + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("iid"u8); + writer.WritePropertyName("actor"u8); if(value != null) { @@ -291,50 +365,35 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "isdeprecated": - var allowedVersionsForIsDeprecated = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsDeprecated.Contains(requestedVersion)) + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("isDeprecated"u8); - - if(value != null) - { - writer.WriteBooleanValue((bool)value); - } - else + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) { - writer.WriteNullValue(); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } } - + + writer.WriteEndArray(); break; - case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("modifiedOn"u8); + writer.WritePropertyName("classKind"u8); if(value != null) { - writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStringValue(((ClassKind)value).ToString()); } else { @@ -342,21 +401,13 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "name": - var allowedVersionsForName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + case "conversionfactor": + if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("name"u8); + writer.WritePropertyName("conversionFactor"u8); if(value != null) { @@ -368,51 +419,89 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "revisionnumber": - var allowedVersionsForRevisionNumber = new List + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("revisionNumber"u8); - - if(value != null) + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) { - writer.WriteNumberValue((int)value); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } } - else + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { - writer.WriteNullValue(); + return; } + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); break; - case "shortname": - var allowedVersionsForShortName = new List + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; + return; + } + + writer.WriteStartArray("hyperLink"u8); - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("shortName"u8); + writer.WritePropertyName("iid"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteStringValue((Guid)value); } else { @@ -420,23 +509,17 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) { return; } - writer.WritePropertyName("thingPreference"u8); + writer.WritePropertyName("isDeprecated"u8); if(value != null) { - writer.WriteStringValue((string)value); + writer.WriteBooleanValue((bool)value); } else { @@ -444,275 +527,122 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; - default: - throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitPrefix"); - } - } - - /// - /// Serializes a into an - /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) - { - if (thing is not UnitPrefix unitPrefix) - { - throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { - writer.WriteStringValue(aliasItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitPrefix.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) { - writer.WriteStringValue(definitionItem); + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitPrefix.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(unitPrefix.IsDeprecated); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(unitPrefix.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitPrefix.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(unitPrefix.ShortName); break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitPrefix.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("name"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitPrefix.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(unitPrefix.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(unitPrefix.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitPrefix.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(unitPrefix.ShortName); break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitPrefix.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { - writer.WriteStringValue(definitionItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) { - writer.WriteStringValue(excludedDomainItem); + writer.WriteNumberValue((int)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(excludedPersonItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { - writer.WriteStringValue(hyperLinkItem); + return; } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitPrefix.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(unitPrefix.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(unitPrefix.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitPrefix.RevisionNumber); writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(unitPrefix.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(unitPrefix.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing UnitPrefix for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(unitPrefix.Actor.HasValue) + + if(value != null) { - writer.WriteStringValue(unitPrefix.Actor.Value); + writer.WriteStringValue((string)value); } else { writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(unitPrefix.ClassKind.ToString()); - writer.WritePropertyName("conversionFactor"u8); - writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { - writer.WriteStringValue(excludedDomainItem); + return; } - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + writer.WritePropertyName("thingPreference"u8); + + if(value != null) { - writer.WriteStringValue(excludedPersonItem); + writer.WriteStringValue((string)value); } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + else { - writer.WriteStringValue(hyperLinkItem); + writer.WriteNullValue(); } - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(unitPrefix.Iid); - writer.WritePropertyName("isDeprecated"u8); - writer.WriteBooleanValue(unitPrefix.IsDeprecated); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(unitPrefix.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(unitPrefix.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(unitPrefix.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(unitPrefix.ThingPreference); break; default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitPrefix"); } - - writer.WriteEndObject(); } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 2e84713ae..017bf8548 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,165 @@ namespace CDP4JsonSerializer /// public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not UserPreference userPreference) + { + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userPreference.Actor.HasValue) + { + writer.WriteStringValue(userPreference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +216,7 @@ public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +224,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +242,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +260,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +278,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +296,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -188,14 +314,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -213,15 +332,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -239,15 +350,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -265,13 +368,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -289,15 +386,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - var allowedVersionsForValue = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForValue.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) { return; } @@ -320,157 +409,21 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not UserPreference userPreference) - { - throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userPreference.Iid); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userPreference.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(userPreference.ShortName); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(userPreference.Value); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userPreference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userPreference.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(userPreference.ShortName); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(userPreference.Value); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userPreference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userPreference.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(userPreference.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(userPreference.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(userPreference.Value); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing UserPreference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(userPreference.Actor.HasValue) - { - writer.WriteStringValue(userPreference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userPreference.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userPreference.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(userPreference.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(userPreference.ThingPreference); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(userPreference.Value); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index 2341cbf1f..e7d7b52e7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,253 @@ namespace CDP4JsonSerializer /// public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not UserRuleVerification userRuleVerification) + { + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(userRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +304,7 @@ public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSeriali /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +312,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,15 +330,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -112,14 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -137,14 +366,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -162,15 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "executedon": - var allowedVersionsForExecutedOn = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExecutedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) { return; } @@ -188,15 +402,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - var allowedVersionsForIid = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -214,15 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - var allowedVersionsForIsActive = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIsActive.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) { return; } @@ -240,14 +438,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -265,15 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -291,15 +474,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rule": - var allowedVersionsForRule = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRule.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) { return; } @@ -317,15 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "status": - var allowedVersionsForStatus = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForStatus.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) { return; } @@ -343,13 +510,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -367,15 +528,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "violation": - var allowedVersionsForViolation = new List - { - "1.0.0", - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForViolation.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) { return; } @@ -398,241 +551,24 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not UserRuleVerification userRuleVerification) - { - throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.0.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.0.0": - Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.0.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WritePropertyName("executedOn"u8); - - if(userRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(userRuleVerification.IsActive); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userRuleVerification.RevisionNumber); - writer.WritePropertyName("rule"u8); - writer.WriteStringValue(userRuleVerification.Rule); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.1.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(userRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(userRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userRuleVerification.RevisionNumber); - writer.WritePropertyName("rule"u8); - writer.WriteStringValue(userRuleVerification.Rule); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.2.0"); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(userRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(userRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userRuleVerification.RevisionNumber); - writer.WritePropertyName("rule"u8); - writer.WriteStringValue(userRuleVerification.Rule); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(userRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing UserRuleVerification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(userRuleVerification.Actor.HasValue) - { - writer.WriteStringValue(userRuleVerification.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("executedOn"u8); - - if(userRuleVerification.ExecutedOn.HasValue) - { - writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); - } - else - { - writer.WriteNullValue(); - } - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(userRuleVerification.Iid); - writer.WritePropertyName("isActive"u8); - writer.WriteBooleanValue(userRuleVerification.IsActive); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(userRuleVerification.RevisionNumber); - writer.WritePropertyName("rule"u8); - writer.WriteStringValue(userRuleVerification.Rule); - writer.WritePropertyName("status"u8); - writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(userRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 81d529ef1..9841c2313 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using System.Linq; using System.Text.Json; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.ReportingData; @@ -49,6 +50,260 @@ namespace CDP4JsonSerializer /// public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + { + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } + + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(valueGroup.Actor.HasValue) + { + writer.WriteStringValue(valueGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -56,6 +311,7 @@ public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer /// The object value to serialize /// The /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { var requestedVersion = requestedDataModelVersion.ToString(3); @@ -63,12 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter switch(propertyName.ToLower()) { case "actor": - var allowedVersionsForActor = new List - { - "1.3.0", - }; - - if(!allowedVersionsForActor.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) { return; } @@ -86,14 +337,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "alias": - var allowedVersionsForAlias = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForAlias.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) { return; } @@ -111,14 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "category": - var allowedVersionsForCategory = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForCategory.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) { return; } @@ -136,14 +373,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "classkind": - var allowedVersionsForClassKind = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForClassKind.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) { return; } @@ -161,14 +391,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - var allowedVersionsForDefinition = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForDefinition.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) { return; } @@ -186,14 +409,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludeddomain": - var allowedVersionsForExcludedDomain = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedDomain.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) { return; } @@ -211,14 +427,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "excludedperson": - var allowedVersionsForExcludedPerson = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForExcludedPerson.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) { return; } @@ -236,14 +445,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "hyperlink": - var allowedVersionsForHyperLink = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForHyperLink.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) { return; } @@ -261,14 +463,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteEndArray(); break; case "iid": - var allowedVersionsForIid = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForIid.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) { return; } @@ -286,14 +481,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - var allowedVersionsForModifiedOn = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForModifiedOn.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) { return; } @@ -311,14 +499,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - var allowedVersionsForName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) { return; } @@ -336,14 +517,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - var allowedVersionsForRevisionNumber = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForRevisionNumber.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) { return; } @@ -361,14 +535,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - var allowedVersionsForShortName = new List - { - "1.1.0", - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForShortName.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) { return; } @@ -386,13 +553,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - var allowedVersionsForThingPreference = new List - { - "1.2.0", - "1.3.0", - }; - - if(!allowedVersionsForThingPreference.Contains(requestedVersion)) + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) { return; } @@ -415,240 +576,25 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } /// - /// Serializes a into an + /// Gets the association between a name of a property and all versions where that property is defined /// - /// The that have to be serialized - /// The - /// The that has been requested for the serialization - /// If the provided is not an - /// If the provided is not supported - public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() { - if (thing is not ValueGroup valueGroup) - { - throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); - } - - if (requestedDataModelVersion < Version.Parse("1.1.0")) - { - Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); - return; - } - - writer.WriteStartObject(); - - switch(requestedDataModelVersion.ToString(3)) - { - case "1.1.0": - Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(valueGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(valueGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(valueGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(valueGroup.ShortName); - break; - case "1.2.0": - Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(valueGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(valueGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(valueGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(valueGroup.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(valueGroup.ThingPreference); - break; - case "1.3.0": - Logger.Log(LogLevel.Debug, "Serializing ValueGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(valueGroup.Actor.HasValue) - { - writer.WriteStringValue(valueGroup.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } - - writer.WriteEndArray(); - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } - - writer.WriteEndArray(); - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(valueGroup.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(valueGroup.Name); - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(valueGroup.RevisionNumber); - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(valueGroup.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(valueGroup.ThingPreference); - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } - - writer.WriteEndObject(); - } + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index e2ec98c55..c989dc7b2 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -22,6 +22,7 @@ [BUMP] To CDP4Common 26.6.0 + README.md 11.0 diff --git a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs index 02d0ce7e4..6d469df8d 100644 --- a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs @@ -140,30 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - public override List Copy { get; set; } } } } From b1227a4f495ec768daa79cad6033063b4188442e Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 14:47:40 +0100 Subject: [PATCH 13/34] Fix deserialization of OrderedItem --- CDP4JsonSerializer/Helper/SerializerHelper.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/CDP4JsonSerializer/Helper/SerializerHelper.cs b/CDP4JsonSerializer/Helper/SerializerHelper.cs index c1f22cfc9..01f7955eb 100644 --- a/CDP4JsonSerializer/Helper/SerializerHelper.cs +++ b/CDP4JsonSerializer/Helper/SerializerHelper.cs @@ -135,23 +135,30 @@ public static IEnumerable ToOrderedItemCollection(this JsonElement foreach (var prop in jsonToken.EnumerateArray()) { - var keyProp = prop.GetProperty("k"); - var valueKind = keyProp.ValueKind; - var key = long.MinValue; + var valueProp = prop.GetProperty("v"); + var valueKind = valueProp.ValueKind; - if (valueKind == JsonValueKind.String) + object valueToAssign = valueKind switch { - key = Convert.ToInt64(keyProp.GetString()); - } - else if (valueKind == JsonValueKind.Number) + JsonValueKind.String => valueProp.GetString(), + JsonValueKind.Number => valueProp.GetInt64(), + _ => null + }; + + var keyProp = prop.GetProperty("k"); + valueKind = keyProp.ValueKind; + + var keyValue = valueKind switch { - key = keyProp.GetInt64(); - } + JsonValueKind.String => long.Parse(keyProp.GetString()!), + JsonValueKind.Number => keyProp.GetInt64(), + _ => long.MinValue + }; var orderedItem = new OrderedItem { - K = key, - V = prop.GetProperty("v").GetString(), + K = keyValue, + V = valueToAssign }; if (prop.TryGetProperty("m", out var value) && value.ValueKind != JsonValueKind.Null) From 3b03b1fcdc61bef8db63de56c8ade663a12aebc2 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 15:07:53 +0100 Subject: [PATCH 14/34] Remove default value for IgnoreCopyProperty for PostOperation serialize --- CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs | 4 ++-- .../JsonConverter/PostOperationJsonConverter.cs | 2 +- CDP4JsonFileDal/JsonFileDal.cs | 4 ++-- CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs | 2 +- CDP4ServicesDal.Tests/PostOperationTestFixture.cs | 2 +- CDP4ServicesDal/CdpServicesDal.cs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs index cb927415d..7e61c9271 100644 --- a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs +++ b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs @@ -55,7 +55,7 @@ public class Cdp4DalJsonSerializer : Cdp4JsonSerializer /// The supported version of the data-model /// /// Asserts that the have to be ignored - public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty = false) + public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty) { this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; this.Initialize(metaInfoProvider, supportedVersion); @@ -65,7 +65,7 @@ public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version support /// Initializes a new instance of the class. /// /// Asserts that the have to be ignored - public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty = false) + public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty) { this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; } diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs index af260a774..37feb0696 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -57,7 +57,7 @@ public class PostOperationJsonConverter: JsonConverter /// Initializes a new instance. /// /// Asserts that the have to be ignored - public PostOperationJsonConverter(bool ignoreCopyProperty = false) + public PostOperationJsonConverter(bool ignoreCopyProperty) { this.ignoreCopyProperty = ignoreCopyProperty; } diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index 160486179..932cea6a3 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -118,7 +118,7 @@ public class JsonFileDal : Dal /// public JsonFileDal() { - this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); } /// @@ -137,7 +137,7 @@ public JsonFileDal(Version dalVersion) this.DalVersion = dalVersion; } - this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); } /// diff --git a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs index 6d469df8d..f06f92662 100644 --- a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs @@ -56,7 +56,7 @@ public class PostOperationTestFixture public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), false); } [Test] diff --git a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs index 6d469df8d..f06f92662 100644 --- a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs @@ -56,7 +56,7 @@ public class PostOperationTestFixture public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), false); } [Test] diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index 9a2a3cd45..18e02b0ea 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -100,7 +100,7 @@ public class CdpServicesDal : Dal /// Asserts that the MessagePack deserialization should be used or not. Supported by default public CdpServicesDal(bool isMessagePackSupported = true) { - this.Cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); this.MessagePackSerializer = new MessagePackSerializer(); this.isMessagePackSupported = isMessagePackSupported; From 066570305433cc541dc686378c260b97004b8712 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 22 Mar 2024 15:19:35 +0100 Subject: [PATCH 15/34] Missing README in CDP4JsonSerializer --- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index c989dc7b2..04a57a63f 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -37,9 +37,10 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - + + + + From c11aa539948c03d67693d4883d62a0d20affc970 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Thu, 24 Oct 2024 10:37:07 +0200 Subject: [PATCH 16/34] Initial commit containing only codegen Serializer and Resolver classes --- .../ActionItemResolver.cs | 289 +++- .../ActualFiniteStateListResolver.cs | 129 +- .../ActualFiniteStateResolver.cs | 118 +- .../AutoGenDtoDeserializer/AliasResolver.cs | 133 +- .../AndExpressionResolver.cs | 107 +- .../ApprovalResolver.cs | 166 +- .../ArrayParameterTypeResolver.cs | 202 ++- .../BinaryNoteResolver.cs | 173 +- .../BinaryRelationshipResolver.cs | 158 +- .../BinaryRelationshipRuleResolver.cs | 213 ++- .../AutoGenDtoDeserializer/BookResolver.cs | 155 +- .../BooleanParameterTypeResolver.cs | 172 +- .../AutoGenDtoDeserializer/BoundsResolver.cs | 155 +- .../BuiltInRuleVerificationResolver.cs | 145 +- .../CategoryResolver.cs | 179 +- .../ChangeProposalResolver.cs | 256 ++- .../ChangeRequestResolver.cs | 245 ++- .../CitationResolver.cs | 155 +- .../AutoGenDtoDeserializer/ColorResolver.cs | 144 +- .../CommonFileStoreResolver.cs | 147 +- .../CompoundParameterTypeResolver.cs | 187 +- .../ConstantResolver.cs | 188 +- .../ContractChangeNoticeResolver.cs | 256 ++- .../CyclicRatioScaleResolver.cs | 267 ++- .../DateParameterTypeResolver.cs | 172 +- .../DateTimeParameterTypeResolver.cs | 172 +- .../DecompositionRuleResolver.cs | 194 ++- .../DefinitionResolver.cs | 137 +- ...ependentParameterTypeAssignmentResolver.cs | 122 +- .../DerivedQuantityKindResolver.cs | 205 ++- .../DerivedUnitResolver.cs | 158 +- .../DiagramCanvasResolver.cs | 136 +- .../DiagramEdgeResolver.cs | 180 +- .../DiagramObjectResolver.cs | 176 +- .../DomainFileStoreResolver.cs | 158 +- .../DomainOfExpertiseGroupResolver.cs | 161 +- .../DomainOfExpertiseResolver.cs | 161 +- .../AutoGenDtoDeserializer/DtoFactory.cs | 39 +- .../ElementDefinitionResolver.cs | 196 ++- .../ElementUsageResolver.cs | 197 ++- .../EmailAddressResolver.cs | 122 +- ...ineeringModelDataDiscussionItemResolver.cs | 155 +- .../EngineeringModelDataNoteResolver.cs | 169 +- .../EngineeringModelResolver.cs | 161 +- .../EngineeringModelSetupResolver.cs | 233 ++- .../EnumerationParameterTypeResolver.cs | 187 +- .../EnumerationValueDefinitionResolver.cs | 143 +- .../ExclusiveOrExpressionResolver.cs | 107 +- .../ExternalIdentifierMapResolver.cs | 173 +- .../AutoGenDtoDeserializer/FileResolver.cs | 136 +- .../FileRevisionResolver.cs | 159 +- .../FileTypeResolver.cs | 172 +- .../AutoGenDtoDeserializer/FolderResolver.cs | 155 +- .../GlossaryResolver.cs | 168 +- .../AutoGenDtoDeserializer/GoalResolver.cs | 150 +- .../HyperLinkResolver.cs | 133 +- .../IdCorrespondenceResolver.cs | 122 +- ...ependentParameterTypeAssignmentResolver.cs | 122 +- .../IntervalScaleResolver.cs | 256 ++- .../IterationResolver.cs | 260 ++- .../IterationSetupResolver.cs | 177 +- .../LinearConversionUnitResolver.cs | 176 +- .../LogEntryChangelogItemResolver.cs | 140 +- .../LogarithmicScaleResolver.cs | 307 +++- .../MappingToReferenceScaleResolver.cs | 122 +- .../ModelLogEntryResolver.cs | 183 +- .../ModelReferenceDataLibraryResolver.cs | 235 ++- .../ModellingThingReferenceResolver.cs | 122 +- .../MultiRelationshipResolver.cs | 143 +- .../MultiRelationshipRuleResolver.cs | 194 ++- .../NaturalLanguageResolver.cs | 133 +- .../NestedElementResolver.cs | 133 +- .../NestedParameterResolver.cs | 166 +- .../NotExpressionResolver.cs | 111 +- .../AutoGenDtoDeserializer/OptionResolver.cs | 157 +- .../OrExpressionResolver.cs | 107 +- .../OrdinalScaleResolver.cs | 267 ++- .../OrganizationResolver.cs | 133 +- .../OrganizationalParticipantResolver.cs | 111 +- .../OwnedStyleResolver.cs | 250 ++- .../AutoGenDtoDeserializer/PageResolver.cs | 155 +- .../ParameterGroupResolver.cs | 122 +- .../ParameterOverrideResolver.cs | 136 +- .../ParameterOverrideValueSetResolver.cs | 146 +- .../ParameterResolver.cs | 213 ++- .../ParameterSubscriptionResolver.cs | 118 +- .../ParameterSubscriptionValueSetResolver.cs | 127 +- .../ParameterTypeComponentResolver.cs | 133 +- .../ParameterValueSetResolver.cs | 158 +- .../ParameterizedCategoryRuleResolver.cs | 172 +- .../ParametricConstraintResolver.cs | 118 +- .../ParticipantPermissionResolver.cs | 133 +- .../ParticipantResolver.cs | 151 +- .../ParticipantRoleResolver.cs | 161 +- .../PersonPermissionResolver.cs | 133 +- .../AutoGenDtoDeserializer/PersonResolver.cs | 253 ++- .../PersonRoleResolver.cs | 161 +- .../AutoGenDtoDeserializer/PointResolver.cs | 133 +- .../PossibleFiniteStateListResolver.cs | 176 +- .../PossibleFiniteStateResolver.cs | 143 +- .../PrefixedUnitResolver.cs | 154 +- .../PublicationResolver.cs | 125 +- .../QuantityKindFactorResolver.cs | 122 +- .../RatioScaleResolver.cs | 256 ++- .../ReferenceSourceResolver.cs | 238 ++- .../ReferencerRuleResolver.cs | 194 ++- .../RelationalExpressionResolver.cs | 138 +- .../RelationshipParameterValueResolver.cs | 127 +- .../RequestForDeviationResolver.cs | 245 ++- .../RequestForWaiverResolver.cs | 245 ++- .../RequirementResolver.cs | 194 ++- ...irementsContainerParameterValueResolver.cs | 127 +- .../RequirementsGroupResolver.cs | 175 +- .../RequirementsSpecificationResolver.cs | 193 ++- .../ReviewItemDiscrepancyResolver.cs | 252 ++- .../RuleVerificationListResolver.cs | 158 +- .../RuleViolationResolver.cs | 118 +- .../SampledFunctionParameterTypeResolver.cs | 196 ++- .../ScaleReferenceQuantityValueResolver.cs | 122 +- .../ScaleValueDefinitionResolver.cs | 154 +- .../AutoGenDtoDeserializer/SectionResolver.cs | 155 +- .../SharedStyleResolver.cs | 250 ++- .../SimpleParameterValueResolver.cs | 127 +- .../SimpleQuantityKindResolver.cs | 201 ++- .../SimpleUnitResolver.cs | 154 +- .../SiteDirectoryDataAnnotationResolver.cs | 169 +- ...SiteDirectoryDataDiscussionItemResolver.cs | 155 +- .../SiteDirectoryResolver.cs | 243 ++- .../SiteDirectoryThingReferenceResolver.cs | 122 +- .../SiteLogEntryResolver.cs | 183 +- .../SiteReferenceDataLibraryResolver.cs | 246 ++- .../SolutionResolver.cs | 155 +- .../SpecializedQuantityKindResolver.cs | 212 ++- .../StakeHolderValueMapResolver.cs | 185 +- .../StakeHolderValueMapSettingsResolver.cs | 133 +- .../StakeholderResolver.cs | 157 +- .../StakeholderValueResolver.cs | 150 +- .../TelephoneNumberResolver.cs | 118 +- .../AutoGenDtoDeserializer/TermResolver.cs | 154 +- .../TextParameterTypeResolver.cs | 172 +- .../TextualNoteResolver.cs | 173 +- .../TimeOfDayParameterTypeResolver.cs | 172 +- .../UnitFactorResolver.cs | 122 +- .../UnitPrefixResolver.cs | 165 +- .../UserPreferenceResolver.cs | 122 +- .../UserRuleVerificationResolver.cs | 145 +- .../ValueGroupResolver.cs | 150 +- .../ActionItemSerializer.cs | 1052 ++++++++++-- .../ActualFiniteStateListSerializer.cs | 589 ++++++- .../ActualFiniteStateSerializer.cs | 475 +++++- .../AutoGenDtoSerializer/AliasSerializer.cs | 476 +++++- .../AndExpressionSerializer.cs | 446 ++++- .../ApprovalSerializer.cs | 542 +++++- .../ArrayParameterTypeSerializer.cs | 905 +++++++++- .../BinaryNoteSerializer.cs | 590 ++++++- .../BinaryRelationshipRuleSerializer.cs | 792 ++++++++- .../BinaryRelationshipSerializer.cs | 606 ++++++- .../AutoGenDtoSerializer/BookSerializer.cs | 584 ++++++- .../BooleanParameterTypeSerializer.cs | 733 +++++++- .../AutoGenDtoSerializer/BoundsSerializer.cs | 515 +++++- .../BuiltInRuleVerificationSerializer.cs | 597 ++++++- .../CategorySerializer.cs | 790 ++++++++- .../ChangeProposalSerializer.cs | 944 +++++++++- .../ChangeRequestSerializer.cs | 917 +++++++++- .../CitationSerializer.cs | 534 +++++- .../AutoGenDtoSerializer/ColorSerializer.cs | 505 +++++- .../CommonFileStoreSerializer.cs | 590 ++++++- .../CompoundParameterTypeSerializer.cs | 819 ++++++++- .../ConstantSerializer.cs | 813 ++++++++- .../ContractChangeNoticeSerializer.cs | 944 +++++++++- .../CyclicRatioScaleSerializer.cs | 1022 +++++++++-- .../DateParameterTypeSerializer.cs | 733 +++++++- .../DateTimeParameterTypeSerializer.cs | 733 +++++++- .../DecompositionRuleSerializer.cs | 827 ++++++++- .../DefinitionSerializer.cs | 618 ++++++- ...endentParameterTypeAssignmentSerializer.cs | 419 ++++- .../DerivedQuantityKindSerializer.cs | 905 +++++++++- .../DerivedUnitSerializer.cs | 704 +++++++- .../DiagramCanvasSerializer.cs | 530 +++++- .../DiagramEdgeSerializer.cs | 761 ++++++++- .../DiagramObjectSerializer.cs | 713 +++++++- .../DomainFileStoreSerializer.cs | 619 ++++++- .../DomainOfExpertiseGroupSerializer.cs | 704 +++++++- .../DomainOfExpertiseSerializer.cs | 704 +++++++- .../ElementDefinitionSerializer.cs | 971 ++++++++++- .../ElementUsageSerializer.cs | 876 +++++++++- .../EmailAddressSerializer.cs | 447 ++++- ...eeringModelDataDiscussionItemSerializer.cs | 542 +++++- .../EngineeringModelDataNoteSerializer.cs | 638 ++++++- .../EngineeringModelSerializer.cs | 762 ++++++++- .../EngineeringModelSetupSerializer.cs | 1080 +++++++++++- .../EnumerationParameterTypeSerializer.cs | 819 ++++++++- .../EnumerationValueDefinitionSerializer.cs | 618 ++++++- .../ExclusiveOrExpressionSerializer.cs | 446 ++++- .../ExternalIdentifierMapSerializer.cs | 656 ++++++- .../FileRevisionSerializer.cs | 627 ++++++- .../AutoGenDtoSerializer/FileSerializer.cs | 597 ++++++- .../FileTypeSerializer.cs | 733 +++++++- .../AutoGenDtoSerializer/FolderSerializer.cs | 570 ++++++- .../GlossarySerializer.cs | 761 ++++++++- .../AutoGenDtoSerializer/GoalSerializer.cs | 626 ++++++- .../HyperLinkSerializer.cs | 476 +++++- .../IdCorrespondenceSerializer.cs | 447 ++++- ...endentParameterTypeAssignmentSerializer.cs | 419 ++++- .../IntervalScaleSerializer.cs | 993 ++++++++++- .../IterationSerializer.cs | 1519 +++++++++++++++-- .../IterationSetupSerializer.cs | 664 ++++++- .../LinearConversionUnitSerializer.cs | 705 +++++++- .../LogEntryChangelogItemSerializer.cs | 465 ++++- .../LogarithmicScaleSerializer.cs | 1166 +++++++++++-- .../MappingToReferenceScaleSerializer.cs | 447 ++++- .../ModelLogEntrySerializer.cs | 780 ++++++++- .../ModelReferenceDataLibrarySerializer.cs | 1367 +++++++++++++-- .../ModellingThingReferenceSerializer.cs | 434 ++++- .../MultiRelationshipRuleSerializer.cs | 791 ++++++++- .../MultiRelationshipSerializer.cs | 605 ++++++- .../NaturalLanguageSerializer.cs | 476 +++++- .../NestedElementSerializer.cs | 561 +++++- .../NestedParameterSerializer.cs | 599 ++++++- .../NotExpressionSerializer.cs | 418 ++++- .../AutoGenDtoSerializer/OptionSerializer.cs | 732 +++++++- .../OrExpressionSerializer.cs | 446 ++++- .../OrdinalScaleSerializer.cs | 1022 +++++++++-- .../OrganizationSerializer.cs | 476 +++++- .../OrganizationalParticipantSerializer.cs | 376 +++- .../OwnedStyleSerializer.cs | 1076 +++++++++++- .../AutoGenDtoSerializer/PageSerializer.cs | 584 ++++++- .../ParameterGroupSerializer.cs | 483 +++++- .../ParameterOverrideSerializer.cs | 561 +++++- .../ParameterOverrideValueSetSerializer.cs | 522 +++++- .../ParameterSerializer.cs | 908 +++++++++- .../ParameterSubscriptionSerializer.cs | 475 +++++- ...ParameterSubscriptionValueSetSerializer.cs | 462 ++++- .../ParameterTypeComponentSerializer.cs | 512 +++++- .../ParameterValueSetSerializer.cs | 623 ++++++- .../ParameterizedCategoryRuleSerializer.cs | 733 +++++++- .../ParametricConstraintSerializer.cs | 511 +++++- .../ParticipantPermissionSerializer.cs | 476 +++++- .../ParticipantRoleSerializer.cs | 704 +++++++- .../ParticipantSerializer.cs | 562 +++++- .../PersonPermissionSerializer.cs | 476 +++++- .../PersonRoleSerializer.cs | 704 +++++++- .../AutoGenDtoSerializer/PersonSerializer.cs | 1088 +++++++++++- .../AutoGenDtoSerializer/PointSerializer.cs | 461 ++++- .../PossibleFiniteStateListSerializer.cs | 826 ++++++++- .../PossibleFiniteStateSerializer.cs | 618 ++++++- .../PrefixedUnitSerializer.cs | 647 ++++++- .../PublicationSerializer.cs | 532 +++++- .../QuantityKindFactorSerializer.cs | 447 ++++- .../RatioScaleSerializer.cs | 993 ++++++++++- .../ReferenceSourceSerializer.cs | 1051 +++++++++++- .../ReferencerRuleSerializer.cs | 791 ++++++++- .../RelationalExpressionSerializer.cs | 527 +++++- .../RelationshipParameterValueSerializer.cs | 475 +++++- .../RequestForDeviationSerializer.cs | 917 +++++++++- .../RequestForWaiverSerializer.cs | 917 +++++++++- .../RequirementSerializer.cs | 912 +++++++++- ...ementsContainerParameterValueSerializer.cs | 475 +++++- .../RequirementsGroupSerializer.cs | 800 ++++++++- .../RequirementsSpecificationSerializer.cs | 886 +++++++++- .../ReviewItemDiscrepancySerializer.cs | 965 ++++++++++- .../RuleVerificationListSerializer.cs | 704 +++++++- .../RuleViolationSerializer.cs | 475 +++++- .../SampledFunctionParameterTypeSerializer.cs | 741 +++++++- .../ScaleReferenceQuantityValueSerializer.cs | 447 ++++- .../ScaleValueDefinitionSerializer.cs | 647 ++++++- .../AutoGenDtoSerializer/SectionSerializer.cs | 584 ++++++- .../SerializerProvider.cs | 65 +- .../SharedStyleSerializer.cs | 1076 +++++++++++- .../SimpleParameterValueSerializer.cs | 498 +++++- .../SimpleQuantityKindSerializer.cs | 848 ++++++++- .../SimpleUnitSerializer.cs | 647 ++++++- .../SiteDirectoryDataAnnotationSerializer.cs | 611 ++++++- ...teDirectoryDataDiscussionItemSerializer.cs | 542 +++++- .../SiteDirectorySerializer.cs | 1253 ++++++++++++-- .../SiteDirectoryThingReferenceSerializer.cs | 434 ++++- .../SiteLogEntrySerializer.cs | 780 ++++++++- .../SiteReferenceDataLibrarySerializer.cs | 1396 +++++++++++++-- .../SolutionSerializer.cs | 515 +++++- .../SpecializedQuantityKindSerializer.cs | 877 +++++++++- .../StakeHolderValueMapSerializer.cs | 866 +++++++++- .../StakeHolderValueMapSettingsSerializer.cs | 542 +++++- .../StakeholderSerializer.cs | 674 +++++++- .../StakeholderValueSerializer.cs | 626 ++++++- .../TelephoneNumberSerializer.cs | 475 +++++- .../AutoGenDtoSerializer/TermSerializer.cs | 647 ++++++- .../TextParameterTypeSerializer.cs | 733 +++++++- .../TextualNoteSerializer.cs | 590 ++++++- .../TimeOfDayParameterTypeSerializer.cs | 733 +++++++- .../UnitFactorSerializer.cs | 447 ++++- .../UnitPrefixSerializer.cs | 676 +++++++- .../UserPreferenceSerializer.cs | 447 ++++- .../UserRuleVerificationSerializer.cs | 597 ++++++- .../ValueGroupSerializer.cs | 626 ++++++- 294 files changed, 105910 insertions(+), 19130 deletions(-) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index f4815aad3..c4c630f61 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,151 +28,287 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actionItem = new CDP4Common.DTO.ActionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actionee"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actionItem.Actionee = jObject["actionee"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var actionItem = new CDP4Common.DTO.ActionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actionee"u8, out var actioneeProperty)) { - actionItem.Actor = jObject["actor"].ToObject(); + if(actioneeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale actionee property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Actionee = actioneeProperty.GetGuid(); + } } - if (!jObject["approvedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - actionItem.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + actionItem.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - actionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - actionItem.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + actionItem.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - actionItem.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["closeOutDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutDate"u8, out var closeOutDateProperty)) { - actionItem.CloseOutDate = jObject["closeOutDate"].ToObject(); + if(closeOutDateProperty.ValueKind == JsonValueKind.Null) + { + actionItem.CloseOutDate = null; + } + else + { + actionItem.CloseOutDate = closeOutDateProperty.GetDateTime(); + } } - if (!jObject["closeOutStatement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutStatement"u8, out var closeOutStatementProperty)) { - actionItem.CloseOutStatement = jObject["closeOutStatement"].ToObject(); + if(closeOutStatementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale closeOutStatement property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CloseOutStatement = closeOutStatementProperty.GetString(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - actionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - actionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - actionItem.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + actionItem.Discussion.Add(element.GetGuid()); + } } - if (!jObject["dueDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dueDate"u8, out var dueDateProperty)) { - actionItem.DueDate = jObject["dueDate"].ToObject(); + if(dueDateProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale dueDate property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.DueDate = dueDateProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - actionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actionItem.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - actionItem.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + actionItem.PrimaryAnnotatedThing = null; + } + else + { + actionItem.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - actionItem.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + actionItem.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - actionItem.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - actionItem.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + actionItem.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - actionItem.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - actionItem.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Title = titleProperty.GetString(); + } } return actionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index c840513ae..5f599126e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,112 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty) && actualStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ActualState.AddRange(jObject["actualState"].ToObject>()); + foreach(var element in actualStateProperty.EnumerateArray()) + { + actualFiniteStateList.ActualState.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actualFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty)) { - actualFiniteStateList.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToOrderedItemCollection()); + actualFiniteStateList.PossibleFiniteStateList.AddRange(possibleFiniteStateListProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index ee6f1001d..97474b0d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - actualFiniteState.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale kind property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.Kind = ActualFiniteStateKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty) && possibleStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.PossibleState.AddRange(jObject["possibleState"].ToObject>()); + foreach(var element in possibleStateProperty.EnumerateArray()) + { + actualFiniteState.PossibleState.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index c72e5fdc6..bb0f859c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AliasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Alias FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var alias = new CDP4Common.DTO.Alias(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AliasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - alias.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var alias = new CDP4Common.DTO.Alias(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - alias.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the alias {id} is null", alias.Iid); + } + else + { + alias.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + alias.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + alias.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isSynonym"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isSynonym"u8, out var isSynonymProperty)) { - alias.IsSynonym = jObject["isSynonym"].ToObject(); + if(isSynonymProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isSynonym property of the alias {id} is null", alias.Iid); + } + else + { + alias.IsSynonym = isSynonymProperty.GetBoolean(); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - alias.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the alias {id} is null", alias.Iid); + } + else + { + alias.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - alias.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the alias {id} is null", alias.Iid); + } + else + { + alias.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - alias.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the alias {id} is null", alias.Iid); + } + else + { + alias.ThingPreference = thingPreferenceProperty.GetString(); + } } return alias; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index 76841ff87..51a6c7418 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AndExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.AndExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.AndExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var andExpression = new CDP4Common.DTO.AndExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AndExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - andExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var andExpression = new CDP4Common.DTO.AndExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + andExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + andExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - andExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - andExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + andExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - andExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return andExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index 88600f96a..1a8acf813 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ApprovalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Approval FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var approval = new CDP4Common.DTO.Approval(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ApprovalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - approval.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var approval = new CDP4Common.DTO.Approval(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - approval.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the approval {id} is null", approval.Iid); + } + else + { + approval.Author = authorProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - approval.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the approval {id} is null", approval.Iid); + } + else + { + approval.Classification = AnnotationApprovalKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - approval.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the approval {id} is null", approval.Iid); + } + else + { + approval.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - approval.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + approval.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + approval.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - approval.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the approval {id} is null", approval.Iid); + } + else + { + approval.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - approval.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - approval.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the approval {id} is null", approval.Iid); + } + else + { + approval.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - approval.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the approval {id} is null", approval.Iid); + } + else + { + approval.ThingPreference = thingPreferenceProperty.GetString(); + } } return approval; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index b73fef9ef..7468710cc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,193 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ArrayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ArrayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - arrayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + arrayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + arrayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - arrayParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + arrayParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + arrayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dimension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dimension"u8, out var dimensionProperty)) { - arrayParameterType.Dimension.AddRange(jObject["dimension"].ToOrderedItemCollection()); + arrayParameterType.Dimension.AddRange(dimensionProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + arrayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + arrayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + arrayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - arrayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - arrayParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isFinalized property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["isTensor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isTensor"u8, out var isTensorProperty)) { - arrayParameterType.IsTensor = jObject["isTensor"].ToObject(); + if(isTensorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isTensor property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsTensor = isTensorProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - arrayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - arrayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - arrayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - arrayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - arrayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return arrayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index ab33fda49..84fd7954e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryNote = new CDP4Common.DTO.BinaryNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["caption"].IsNullOrEmpty()) + var binaryNote = new CDP4Common.DTO.BinaryNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("caption"u8, out var captionProperty)) { - binaryNote.Caption = jObject["caption"].ToObject(); + if(captionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale caption property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Caption = captionProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryNote.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - binaryNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - binaryNote.FileType = jObject["fileType"].ToObject(); + if(fileTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fileType property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.FileType = fileTypeProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index be5c2b92f..b324a7a2d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + binaryRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - binaryRelationship.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - binaryRelationship.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale target property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index 9cca314ad..ee15b3b01 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,199 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - binaryRelationshipRule.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipRuleResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["definition"].IsNullOrEmpty()) + var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + binaryRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + binaryRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["forwardRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ForwardRelationshipName = jObject["forwardRelationshipName"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("forwardRelationshipName"u8, out var forwardRelationshipNameProperty)) { - binaryRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + if(forwardRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale forwardRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ForwardRelationshipName = forwardRelationshipNameProperty.GetString(); + } } - if (!jObject["inverseRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.InverseRelationshipName = jObject["inverseRelationshipName"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + binaryRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("inverseRelationshipName"u8, out var inverseRelationshipNameProperty)) { - binaryRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(inverseRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale inverseRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.InverseRelationshipName = inverseRelationshipNameProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - binaryRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationshipRule.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - binaryRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationshipCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["sourceCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryRelationshipRule.SourceCategory = jObject["sourceCategory"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["targetCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceCategory"u8, out var sourceCategoryProperty)) { - binaryRelationshipRule.TargetCategory = jObject["targetCategory"].ToObject(); - } + if(sourceCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale sourceCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.SourceCategory = sourceCategoryProperty.GetGuid(); + } + } + + if (jsonElement.TryGetProperty("targetCategory"u8, out var targetCategoryProperty)) + { + if(targetCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale targetCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.TargetCategory = targetCategoryProperty.GetGuid(); + } + } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index e8798e510..ec7c73f59 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BookResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Book FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var book = new CDP4Common.DTO.Book(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BookResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - book.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var book = new CDP4Common.DTO.Book(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - book.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + book.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - book.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the book {id} is null", book.Iid); + } + else + { + book.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + book.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + book.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - book.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the book {id} is null", book.Iid); + } + else + { + book.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - book.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the book {id} is null", book.Iid); + } + else + { + book.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - book.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the book {id} is null", book.Iid); + } + else + { + book.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["section"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("section"u8, out var sectionProperty)) { - book.Section.AddRange(jObject["section"].ToOrderedItemCollection()); + book.Section.AddRange(sectionProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - book.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the book {id} is null", book.Iid); + } + else + { + book.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - book.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the book {id} is null", book.Iid); + } + else + { + book.ThingPreference = thingPreferenceProperty.GetString(); + } } return book; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index 23f9588e2..3adccd1fb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BooleanParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BooleanParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - booleanParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + booleanParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + booleanParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + booleanParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + booleanParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + booleanParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + booleanParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - booleanParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - booleanParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - booleanParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - booleanParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - booleanParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - booleanParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return booleanParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index 50d6680de..2ab0b5091 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BoundsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Bounds FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var bounds = new CDP4Common.DTO.Bounds(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BoundsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - bounds.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var bounds = new CDP4Common.DTO.Bounds(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + bounds.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + bounds.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["height"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("height"u8, out var heightProperty)) { - bounds.Height = jObject["height"].ToObject(); + if(heightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale height property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Height = heightProperty.GetSingle(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - bounds.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - bounds.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - bounds.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["width"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("width"u8, out var widthProperty)) { - bounds.Width = jObject["width"].ToObject(); + if(widthProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale width property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Width = widthProperty.GetSingle(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - bounds.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale x property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - bounds.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale y property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Y = yProperty.GetSingle(); + } } return bounds; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index 60c629a3c..98ff206db 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BuiltInRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - builtInRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BuiltInRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - builtInRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - builtInRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + builtInRuleVerification.ExecutedOn = null; + } + else + { + builtInRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - builtInRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - builtInRuleVerification.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - builtInRuleVerification.Status = jObject["status"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - builtInRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - builtInRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return builtInRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index 2f6785e9d..136302465 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,167 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CategoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Category FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var category = new CDP4Common.DTO.Category(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CategoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - category.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var category = new CDP4Common.DTO.Category(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - category.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + category.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - category.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + category.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + category.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + category.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - category.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + category.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isAbstract"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) { - category.IsAbstract = jObject["isAbstract"].ToObject(); + if(isAbstractProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isAbstract property of the category {id} is null", category.Iid); + } + else + { + category.IsAbstract = isAbstractProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - category.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the category {id} is null", category.Iid); + } + else + { + category.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - category.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the category {id} is null", category.Iid); + } + else + { + category.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - category.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the category {id} is null", category.Iid); + } + else + { + category.Name = nameProperty.GetString(); + } } - if (!jObject["permissibleClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("permissibleClass"u8, out var permissibleClassProperty) && permissibleClassProperty.ValueKind != JsonValueKind.Null) { - category.PermissibleClass.AddRange(jObject["permissibleClass"].ToObject>()); + foreach(var element in permissibleClassProperty.EnumerateArray()) + { + category.PermissibleClass.Add(ClassKindDeserializer.Deserialize(element)); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - category.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the category {id} is null", category.Iid); + } + else + { + category.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["superCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("superCategory"u8, out var superCategoryProperty) && superCategoryProperty.ValueKind != JsonValueKind.Null) { - category.SuperCategory.AddRange(jObject["superCategory"].ToObject>()); + foreach(var element in superCategoryProperty.EnumerateArray()) + { + category.SuperCategory.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - category.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the category {id} is null", category.Iid); + } + else + { + category.ThingPreference = thingPreferenceProperty.GetString(); + } } return category; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index a19595710..d7fd3c3d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeProposalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeProposal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeProposal = new CDP4Common.DTO.ChangeProposal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeProposalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeProposal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeProposal = new CDP4Common.DTO.ChangeProposal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeProposal.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeProposal.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeProposal.Category.Add(element.GetGuid()); + } } - if (!jObject["changeRequest"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeRequest"u8, out var changeRequestProperty)) { - changeProposal.ChangeRequest = jObject["changeRequest"].ToObject(); + if(changeRequestProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeRequest property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ChangeRequest = changeRequestProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeProposal.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeProposal.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeProposal.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeProposal.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeProposal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeProposal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeProposal.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeProposal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeProposal.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeProposal.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeProposal.PrimaryAnnotatedThing = null; + } + else + { + changeProposal.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeProposal.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeProposal.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeProposal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeProposal.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeProposal.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeProposal.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeProposal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeProposal.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Title = titleProperty.GetString(); + } } return changeProposal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index 43d6c202f..65ee35157 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeRequestResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeRequest FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeRequest = new CDP4Common.DTO.ChangeRequest(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeRequestResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeRequest.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeRequest = new CDP4Common.DTO.ChangeRequest(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeRequest.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeRequest.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeRequest.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeRequest.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeRequest.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeRequest.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeRequest.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeRequest.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeRequest.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeRequest.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeRequest.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeRequest.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeRequest.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeRequest.PrimaryAnnotatedThing = null; + } + else + { + changeRequest.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeRequest.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeRequest.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeRequest.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeRequest.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeRequest.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeRequest.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeRequest.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeRequest.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Title = titleProperty.GetString(); + } } return changeRequest; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index 18098e9ab..aef860fc3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CitationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Citation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var citation = new CDP4Common.DTO.Citation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CitationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - citation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var citation = new CDP4Common.DTO.Citation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + citation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + citation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isAdaptation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAdaptation"u8, out var isAdaptationProperty)) { - citation.IsAdaptation = jObject["isAdaptation"].ToObject(); + if(isAdaptationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isAdaptation property of the citation {id} is null", citation.Iid); + } + else + { + citation.IsAdaptation = isAdaptationProperty.GetBoolean(); + } } - if (!jObject["location"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("location"u8, out var locationProperty)) { - citation.Location = jObject["location"].ToObject(); + if(locationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale location property of the citation {id} is null", citation.Iid); + } + else + { + citation.Location = locationProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - citation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the citation {id} is null", citation.Iid); + } + else + { + citation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["remark"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("remark"u8, out var remarkProperty)) { - citation.Remark = jObject["remark"].ToObject(); + if(remarkProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale remark property of the citation {id} is null", citation.Iid); + } + else + { + citation.Remark = remarkProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - citation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the citation {id} is null", citation.Iid); + } + else + { + citation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - citation.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the citation {id} is null", citation.Iid); + } + else + { + citation.Source = sourceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - citation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the citation {id} is null", citation.Iid); + } + else + { + citation.ThingPreference = thingPreferenceProperty.GetString(); + } } return citation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index 4b0355c98..ca61938e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ColorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Color FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var color = new CDP4Common.DTO.Color(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ColorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - color.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["blue"].IsNullOrEmpty()) + var color = new CDP4Common.DTO.Color(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("blue"u8, out var blueProperty)) { - color.Blue = jObject["blue"].ToObject(); + if(blueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale blue property of the color {id} is null", color.Iid); + } + else + { + color.Blue = blueProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + color.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + color.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["green"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("green"u8, out var greenProperty)) { - color.Green = jObject["green"].ToObject(); + if(greenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale green property of the color {id} is null", color.Iid); + } + else + { + color.Green = greenProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - color.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the color {id} is null", color.Iid); + } + else + { + color.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - color.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the color {id} is null", color.Iid); + } + else + { + color.Name = nameProperty.GetString(); + } } - if (!jObject["red"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("red"u8, out var redProperty)) { - color.Red = jObject["red"].ToObject(); + if(redProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale red property of the color {id} is null", color.Iid); + } + else + { + color.Red = redProperty.GetInt32(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - color.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the color {id} is null", color.Iid); + } + else + { + color.ThingPreference = thingPreferenceProperty.GetString(); + } } return color; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index 329f0ee97..0969d7170 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,131 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CommonFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CommonFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CommonFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - commonFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - commonFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + commonFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + commonFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + commonFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + commonFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - commonFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - commonFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - commonFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - commonFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return commonFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index a2f2e6026..39482bbd2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,176 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CompoundParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CompoundParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - compoundParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + compoundParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + compoundParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - compoundParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + compoundParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + compoundParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + compoundParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + compoundParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + compoundParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - compoundParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - compoundParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isFinalized property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - compoundParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - compoundParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - compoundParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - compoundParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - compoundParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return compoundParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index 498bde5a1..8b0bdcc64 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,175 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ConstantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Constant FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var constant = new CDP4Common.DTO.Constant(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - constant.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ConstantResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - constant.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var constant = new CDP4Common.DTO.Constant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - constant.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + constant.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - constant.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + constant.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + constant.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + constant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - constant.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + constant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - constant.IsDeprecated = jObject["isDeprecated"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + constant.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - constant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the constant {id} is null", constant.Iid); + } + else + { + constant.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - constant.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the constant {id} is null", constant.Iid); + } + else + { + constant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - constant.ParameterType = jObject["parameterType"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the constant {id} is null", constant.Iid); + } + else + { + constant.Name = nameProperty.GetString(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - constant.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the constant {id} is null", constant.Iid); + } + else + { + constant.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - constant.ShortName = jObject["shortName"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + constant.Scale = null; + } + else + { + constant.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - constant.ThingPreference = jObject["thingPreference"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the constant {id} is null", constant.Iid); + } + else + { + constant.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the constant {id} is null", constant.Iid); + } + else + { + constant.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - constant.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + constant.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return constant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index 099c36b58..2e9024570 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ContractChangeNoticeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ContractChangeNoticeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - contractChangeNotice.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + contractChangeNotice.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - contractChangeNotice.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + contractChangeNotice.Category.Add(element.GetGuid()); + } } - if (!jObject["changeProposal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeProposal"u8, out var changeProposalProperty)) { - contractChangeNotice.ChangeProposal = jObject["changeProposal"].ToObject(); + if(changeProposalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeProposal property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ChangeProposal = changeProposalProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - contractChangeNotice.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - contractChangeNotice.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - contractChangeNotice.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + contractChangeNotice.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - contractChangeNotice.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - contractChangeNotice.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - contractChangeNotice.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - contractChangeNotice.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + contractChangeNotice.PrimaryAnnotatedThing = null; + } + else + { + contractChangeNotice.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + contractChangeNotice.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - contractChangeNotice.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + contractChangeNotice.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - contractChangeNotice.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - contractChangeNotice.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - contractChangeNotice.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Title = titleProperty.GetString(); + } } return contractChangeNotice; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index 38c59f764..130ac64a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,263 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CyclicRatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CyclicRatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - cyclicRatioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + cyclicRatioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + cyclicRatioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + cyclicRatioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - cyclicRatioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - cyclicRatioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - cyclicRatioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + cyclicRatioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - cyclicRatioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - cyclicRatioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - cyclicRatioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["modulus"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modulus"u8, out var modulusProperty)) { - cyclicRatioScale.Modulus = jObject["modulus"].ToObject(); + if(modulusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modulus property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Modulus = modulusProperty.GetString(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - cyclicRatioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - cyclicRatioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - cyclicRatioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - cyclicRatioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - cyclicRatioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - cyclicRatioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - cyclicRatioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + cyclicRatioScale.ValueDefinition.Add(element.GetGuid()); + } } return cyclicRatioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index 71c492f1c..0d19d7dbf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateParameterType = new CDP4Common.DTO.DateParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateParameterType = new CDP4Common.DTO.DateParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index 09b106e7f..259457721 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateTimeParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateTimeParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateTimeParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateTimeParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateTimeParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateTimeParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateTimeParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateTimeParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateTimeParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateTimeParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateTimeParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateTimeParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateTimeParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateTimeParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index 126fa16dd..a179dc8eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DecompositionRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DecompositionRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DecompositionRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - decompositionRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + decompositionRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["containedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedCategory"u8, out var containedCategoryProperty) && containedCategoryProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ContainedCategory.AddRange(jObject["containedCategory"].ToObject>()); + foreach(var element in containedCategoryProperty.EnumerateArray()) + { + decompositionRule.ContainedCategory.Add(element.GetGuid()); + } } - if (!jObject["containingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containingCategory"u8, out var containingCategoryProperty)) { - decompositionRule.ContainingCategory = jObject["containingCategory"].ToObject(); + if(containingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale containingCategory property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ContainingCategory = containingCategoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + decompositionRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + decompositionRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + decompositionRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + decompositionRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - decompositionRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxContained"u8, out var maxContainedProperty)) { - decompositionRule.MaxContained = jObject["maxContained"].ToObject(); + if(maxContainedProperty.ValueKind == JsonValueKind.Null) + { + decompositionRule.MaxContained = null; + } + else + { + decompositionRule.MaxContained = maxContainedProperty.GetInt32(); + } } - if (!jObject["minContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minContained"u8, out var minContainedProperty)) { - decompositionRule.MinContained = jObject["minContained"].ToObject(); + if(minContainedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minContained property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.MinContained = minContainedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - decompositionRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - decompositionRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - decompositionRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - decompositionRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return decompositionRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 9cdbcf60a..3dbfce7c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,121 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Definition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var definition = new CDP4Common.DTO.Definition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - definition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["citation"].IsNullOrEmpty()) + var definition = new CDP4Common.DTO.Definition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("citation"u8, out var citationProperty) && citationProperty.ValueKind != JsonValueKind.Null) { - definition.Citation.AddRange(jObject["citation"].ToObject>()); + foreach(var element in citationProperty.EnumerateArray()) + { + definition.Citation.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - definition.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the definition {id} is null", definition.Iid); + } + else + { + definition.Content = contentProperty.GetString(); + } } - if (!jObject["example"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("example"u8, out var exampleProperty)) { - definition.Example.AddRange(jObject["example"].ToOrderedItemCollection()); + definition.Example.AddRange(exampleProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + definition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + definition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - definition.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the definition {id} is null", definition.Iid); + } + else + { + definition.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - definition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the definition {id} is null", definition.Iid); + } + else + { + definition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - definition.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + definition.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - definition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the definition {id} is null", definition.Iid); + } + else + { + definition.ThingPreference = thingPreferenceProperty.GetString(); + } } return definition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index 4ee74b7a7..6cba47589 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dependentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - dependentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + dependentParameterTypeAssignment.MeasurementScale = null; + } + else + { + dependentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dependentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - dependentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dependentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return dependentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index cf14ccdf5..90fecb3f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,196 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + derivedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - derivedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + derivedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - derivedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["quantityKindFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKindFactor"u8, out var quantityKindFactorProperty)) { - derivedQuantityKind.QuantityKindFactor.AddRange(jObject["quantityKindFactor"].ToOrderedItemCollection()); + derivedQuantityKind.QuantityKindFactor.AddRange(quantityKindFactorProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - derivedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return derivedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index e48190dac..4346800f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unitFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitFactor"u8, out var unitFactorProperty)) { - derivedUnit.UnitFactor.AddRange(jObject["unitFactor"].ToOrderedItemCollection()); + derivedUnit.UnitFactor.AddRange(unitFactorProperty.ToOrderedItemCollection()); } return derivedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index 36d78c868..7ded4b613 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramCanvasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramCanvasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramCanvas.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramCanvas.Bounds.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - diagramCanvas.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramCanvas.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramCanvas.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramCanvas.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramCanvas.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramCanvas.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramCanvas.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramCanvas; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index d4aba04df..dd993465d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,168 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramEdgeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramEdge FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramEdgeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramEdge.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramEdge.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramEdge.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.DepictedThing = null; + } + else + { + diagramEdge.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramEdge.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramEdge.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramEdge.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramEdge.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramEdge.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramEdge.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Name = nameProperty.GetString(); + } } - if (!jObject["point"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("point"u8, out var pointProperty)) { - diagramEdge.Point.AddRange(jObject["point"].ToOrderedItemCollection()); + diagramEdge.Point.AddRange(pointProperty.ToOrderedItemCollection()); } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramEdge.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.SharedStyle = null; + } + else + { + diagramEdge.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - diagramEdge.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - diagramEdge.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale target property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramEdge.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramEdge; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index c492282e5..4477d81ce 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramObjectResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramObject FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramObject = new CDP4Common.DTO.DiagramObject(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramObjectResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramObject.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramObject = new CDP4Common.DTO.DiagramObject(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramObject.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramObject.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramObject.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.DepictedThing = null; + } + else + { + diagramObject.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramObject.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramObject.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["documentation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("documentation"u8, out var documentationProperty)) { - diagramObject.Documentation = jObject["documentation"].ToObject(); + if(documentationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale documentation property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Documentation = documentationProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramObject.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramObject.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramObject.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramObject.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramObject.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramObject.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Name = nameProperty.GetString(); + } } - if (!jObject["resolution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("resolution"u8, out var resolutionProperty)) { - diagramObject.Resolution = jObject["resolution"].ToObject(); + if(resolutionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale resolution property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Resolution = resolutionProperty.GetSingle(); + } } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramObject.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.SharedStyle = null; + } + else + { + diagramObject.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramObject.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramObject; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index 156902fd2..1f173b3d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - domainFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + domainFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + domainFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["isHidden"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isHidden"u8, out var isHiddenProperty)) { - domainFileStore.IsHidden = jObject["isHidden"].ToObject(); + if(isHiddenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isHidden property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.IsHidden = isHiddenProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - domainFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index 73de42982..59571a59a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertiseGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertiseGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertiseGroup.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertiseGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertiseGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertiseGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertiseGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertiseGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index f963450d4..e81c0408d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertise.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertise.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + domainOfExpertise.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertise.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertise.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertise.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertise.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertise.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertise.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertise.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertise; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs index 093dde44f..2ba7c5a7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs @@ -1,19 +1,17 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. +// +// Copyright (c) 2015-2023 RHEA System S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Jaime Bernar // -// This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! +// This file is part of CDP4-SDK Community Edition // -// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// The CDP4-SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. @@ -31,11 +29,10 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - - using CDP4Common.DTO; - - using Newtonsoft.Json.Linq; - + using System.Text.Json; + + using CDP4Common.DTO; + /// /// Utility class that is responsible for instantiating a /// @@ -44,7 +41,7 @@ public static class DtoFactory /// /// The type to Constructor map /// - private static readonly Dictionary> DtoConstructorMap = new Dictionary> + private static readonly Dictionary> DtoConstructorMap = new() { { "ActionItem", ActionItemResolver.FromJsonObject }, { "ActualFiniteState", ActualFiniteStateResolver.FromJsonObject }, @@ -195,20 +192,20 @@ public static class DtoFactory }; /// - /// Instantiates a new from a + /// Instantiates a new from a /// - /// The containing the data + /// The containing the data /// The to instantiate - public static Thing ToDto(this JObject dataObject) + public static Thing ToDto(this JsonElement dataObject) { - var classKind = dataObject["classKind"].ToString(); - Func constructor; - if (!DtoConstructorMap.TryGetValue(classKind, out constructor)) + var classKind = dataObject.GetProperty("classKind").ToString(); + + if(!DtoConstructorMap.TryGetValue(classKind, out var constructor)) { throw new InvalidOperationException($"The dto resolver was not found for {classKind}"); } - return constructor(dataObject); + return constructor.Invoke(dataObject); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index c5b2b68e1..5713aa4f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,187 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementDefinition.Category.Add(element.GetGuid()); + } } - if (!jObject["containedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedElement"u8, out var containedElementProperty) && containedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ContainedElement.AddRange(jObject["containedElement"].ToObject>()); + foreach(var element in containedElementProperty.EnumerateArray()) + { + elementDefinition.ContainedElement.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + elementDefinition.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementDefinition.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty) && parameterProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Parameter.AddRange(jObject["parameter"].ToObject>()); + foreach(var element in parameterProperty.EnumerateArray()) + { + elementDefinition.Parameter.Add(element.GetGuid()); + } } - if (!jObject["parameterGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterGroup"u8, out var parameterGroupProperty) && parameterGroupProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ParameterGroup.AddRange(jObject["parameterGroup"].ToObject>()); + foreach(var element in parameterGroupProperty.EnumerateArray()) + { + elementDefinition.ParameterGroup.Add(element.GetGuid()); + } } - if (!jObject["referencedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedElement"u8, out var referencedElementProperty) && referencedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ReferencedElement.AddRange(jObject["referencedElement"].ToObject>()); + foreach(var element in referencedElementProperty.EnumerateArray()) + { + elementDefinition.ReferencedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index 8304d5c3e..56f20ecfe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,187 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementUsageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementUsage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementUsage = new CDP4Common.DTO.ElementUsage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementUsageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementUsage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementUsage = new CDP4Common.DTO.ElementUsage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementUsage.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementUsage.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementUsage.Definition.Add(element.GetGuid()); + } } - if (!jObject["elementDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("elementDefinition"u8, out var elementDefinitionProperty)) { - elementUsage.ElementDefinition = jObject["elementDefinition"].ToObject(); + if(elementDefinitionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale elementDefinition property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ElementDefinition = elementDefinitionProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementUsage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementUsage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + elementUsage.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementUsage.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementUsage.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interfaceEnd"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("interfaceEnd"u8, out var interfaceEndProperty)) { - elementUsage.InterfaceEnd = jObject["interfaceEnd"].ToObject(); + if(interfaceEndProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale interfaceEnd property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.InterfaceEnd = InterfaceEndKindDeserializer.Deserialize(interfaceEndProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementUsage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementUsage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementUsage.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterOverride"u8, out var parameterOverrideProperty) && parameterOverrideProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ParameterOverride.AddRange(jObject["parameterOverride"].ToObject>()); + foreach(var element in parameterOverrideProperty.EnumerateArray()) + { + elementUsage.ParameterOverride.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementUsage.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementUsage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementUsage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index 7ff870419..7d7d3bea3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EmailAddressResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EmailAddress FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var emailAddress = new CDP4Common.DTO.EmailAddress(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EmailAddressResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - emailAddress.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var emailAddress = new CDP4Common.DTO.EmailAddress(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + emailAddress.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + emailAddress.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - emailAddress.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - emailAddress.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - emailAddress.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty)) { - emailAddress.VcardType = jObject["vcardType"].ToObject(); + if(vcardTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.VcardType = VcardEmailAddressKindDeserializer.Deserialize(vcardTypeProperty); + } } return emailAddress; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index e1b8bf451..4a27537a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - engineeringModelDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataDiscussionItem.ReplyTo = null; + } + else + { + engineeringModelDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index 9f56bd581..5c1508d82 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataNote.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + engineeringModelDataNote.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - engineeringModelDataNote.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataNote.PrimaryAnnotatedThing = null; + } + else + { + engineeringModelDataNote.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + engineeringModelDataNote.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index 8eacdcadd..aeac88ff6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,148 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModel FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModel.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["book"].IsNullOrEmpty()) + var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("book"u8, out var bookProperty)) { - engineeringModel.Book.AddRange(jObject["book"].ToOrderedItemCollection()); + engineeringModel.Book.AddRange(bookProperty.ToOrderedItemCollection()); } - if (!jObject["commonFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("commonFileStore"u8, out var commonFileStoreProperty) && commonFileStoreProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.CommonFileStore.AddRange(jObject["commonFileStore"].ToObject>()); + foreach(var element in commonFileStoreProperty.EnumerateArray()) + { + engineeringModel.CommonFileStore.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelSetup"u8, out var engineeringModelSetupProperty)) { - engineeringModel.EngineeringModelSetup = jObject["engineeringModelSetup"].ToObject(); + if(engineeringModelSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale engineeringModelSetup property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.EngineeringModelSetup = engineeringModelSetupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModel.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModel.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["genericNote"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("genericNote"u8, out var genericNoteProperty) && genericNoteProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.GenericNote.AddRange(jObject["genericNote"].ToObject>()); + foreach(var element in genericNoteProperty.EnumerateArray()) + { + engineeringModel.GenericNote.Add(element.GetGuid()); + } } - if (!jObject["iteration"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iteration"u8, out var iterationProperty) && iterationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.Iteration.AddRange(jObject["iteration"].ToObject>()); + foreach(var element in iterationProperty.EnumerateArray()) + { + engineeringModel.Iteration.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - engineeringModel.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale lastModifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + engineeringModel.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["modellingAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modellingAnnotation"u8, out var modellingAnnotationProperty) && modellingAnnotationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ModellingAnnotation.AddRange(jObject["modellingAnnotation"].ToObject>()); + foreach(var element in modellingAnnotationProperty.EnumerateArray()) + { + engineeringModel.ModellingAnnotation.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModel.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModel.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModel; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index 3b1a4fe15..1ce062d0a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,227 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["activeDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelSetup.ActiveDomain.AddRange(jObject["activeDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("activeDomain"u8, out var activeDomainProperty) && activeDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Actor = jObject["actor"].ToObject(); + foreach(var element in activeDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ActiveDomain.Add(element.GetGuid()); + } } - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + engineeringModelSetup.Alias.Add(element.GetGuid()); + } } - if (!jObject["defaultOrganizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOrganizationalParticipant"u8, out var defaultOrganizationalParticipantProperty)) { - engineeringModelSetup.DefaultOrganizationalParticipant = jObject["defaultOrganizationalParticipant"].ToObject(); + if(defaultOrganizationalParticipantProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.DefaultOrganizationalParticipant = null; + } + else + { + engineeringModelSetup.DefaultOrganizationalParticipant = defaultOrganizationalParticipantProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + engineeringModelSetup.Definition.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelIid"u8, out var engineeringModelIidProperty)) { - engineeringModelSetup.EngineeringModelIid = jObject["engineeringModelIid"].ToObject(); + if(engineeringModelIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale engineeringModelIid property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.EngineeringModelIid = engineeringModelIidProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + engineeringModelSetup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty) && iterationSetupProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.IterationSetup.AddRange(jObject["iterationSetup"].ToObject>()); + foreach(var element in iterationSetupProperty.EnumerateArray()) + { + engineeringModelSetup.IterationSetup.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - engineeringModelSetup.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale kind property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Kind = EngineeringModelKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - engineeringModelSetup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + engineeringModelSetup.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["participant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participant"u8, out var participantProperty) && participantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Participant.AddRange(jObject["participant"].ToObject>()); + foreach(var element in participantProperty.EnumerateArray()) + { + engineeringModelSetup.Participant.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty) && requiredRdlProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.RequiredRdl.AddRange(jObject["requiredRdl"].ToObject>()); + foreach(var element in requiredRdlProperty.EnumerateArray()) + { + engineeringModelSetup.RequiredRdl.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - engineeringModelSetup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceEngineeringModelSetupIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceEngineeringModelSetupIid"u8, out var sourceEngineeringModelSetupIidProperty)) { - engineeringModelSetup.SourceEngineeringModelSetupIid = jObject["sourceEngineeringModelSetupIid"].ToObject(); + if(sourceEngineeringModelSetupIidProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.SourceEngineeringModelSetupIid = null; + } + else + { + engineeringModelSetup.SourceEngineeringModelSetupIid = sourceEngineeringModelSetupIidProperty.GetGuid(); + } } - if (!jObject["studyPhase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("studyPhase"u8, out var studyPhaseProperty)) { - engineeringModelSetup.StudyPhase = jObject["studyPhase"].ToObject(); + if(studyPhaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale studyPhase property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.StudyPhase = StudyPhaseKindDeserializer.Deserialize(studyPhaseProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index a6f30859f..d3837abd6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,176 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["allowMultiSelect"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("allowMultiSelect"u8, out var allowMultiSelectProperty)) { - enumerationParameterType.AllowMultiSelect = jObject["allowMultiSelect"].ToObject(); + if(allowMultiSelectProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale allowMultiSelect property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.AllowMultiSelect = allowMultiSelectProperty.GetBoolean(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + enumerationParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - enumerationParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - enumerationParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty)) { - enumerationParameterType.ValueDefinition.AddRange(jObject["valueDefinition"].ToOrderedItemCollection()); + enumerationParameterType.ValueDefinition.AddRange(valueDefinitionProperty.ToOrderedItemCollection()); } return enumerationParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index bb9df663f..5fa2053af 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return enumerationValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index c1d3c2fe5..1f8ab3861 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExclusiveOrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExclusiveOrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - exclusiveOrExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - exclusiveOrExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + exclusiveOrExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - exclusiveOrExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return exclusiveOrExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index 68ed0909c..04c37e0ff 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExternalIdentifierMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExternalIdentifierMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - externalIdentifierMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["correspondence"].IsNullOrEmpty()) + var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("correspondence"u8, out var correspondenceProperty) && correspondenceProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.Correspondence.AddRange(jObject["correspondence"].ToObject>()); + foreach(var element in correspondenceProperty.EnumerateArray()) + { + externalIdentifierMap.Correspondence.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalFormat"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalFormat"u8, out var externalFormatProperty)) { - externalIdentifierMap.ExternalFormat = jObject["externalFormat"].ToObject(); + if(externalFormatProperty.ValueKind == JsonValueKind.Null) + { + externalIdentifierMap.ExternalFormat = null; + } + else + { + externalIdentifierMap.ExternalFormat = externalFormatProperty.GetGuid(); + } } - if (!jObject["externalModelName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalModelName"u8, out var externalModelNameProperty)) { - externalIdentifierMap.ExternalModelName = jObject["externalModelName"].ToObject(); + if(externalModelNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalModelName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalModelName = externalModelNameProperty.GetString(); + } } - if (!jObject["externalToolName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolName"u8, out var externalToolNameProperty)) { - externalIdentifierMap.ExternalToolName = jObject["externalToolName"].ToObject(); + if(externalToolNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalToolName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolName = externalToolNameProperty.GetString(); + } } - if (!jObject["externalToolVersion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolVersion"u8, out var externalToolVersionProperty)) { - externalIdentifierMap.ExternalToolVersion = jObject["externalToolVersion"].ToObject(); + if(externalToolVersionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalToolVersion property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolVersion = externalToolVersionProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - externalIdentifierMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - externalIdentifierMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - externalIdentifierMap.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - externalIdentifierMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ThingPreference = thingPreferenceProperty.GetString(); + } } return externalIdentifierMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index ccd2777e4..c07ae429c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.File FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var file = new CDP4Common.DTO.File(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - file.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var file = new CDP4Common.DTO.File(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - file.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + file.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + file.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + file.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileRevision"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileRevision"u8, out var fileRevisionProperty) && fileRevisionProperty.ValueKind != JsonValueKind.Null) { - file.FileRevision.AddRange(jObject["fileRevision"].ToObject>()); + foreach(var element in fileRevisionProperty.EnumerateArray()) + { + file.FileRevision.Add(element.GetGuid()); + } } - if (!jObject["lockedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lockedBy"u8, out var lockedByProperty)) { - file.LockedBy = jObject["lockedBy"].ToObject(); + if(lockedByProperty.ValueKind == JsonValueKind.Null) + { + file.LockedBy = null; + } + else + { + file.LockedBy = lockedByProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - file.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the file {id} is null", file.Iid); + } + else + { + file.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - file.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the file {id} is null", file.Iid); + } + else + { + file.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - file.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the file {id} is null", file.Iid); + } + else + { + file.ThingPreference = thingPreferenceProperty.GetString(); + } } return file; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index 50725bbf8..183011498 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileRevisionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileRevision FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileRevision = new CDP4Common.DTO.FileRevision(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileRevisionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileRevision.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var fileRevision = new CDP4Common.DTO.FileRevision(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - fileRevision.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + fileRevision.ContainingFolder = null; + } + else + { + fileRevision.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["contentHash"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("contentHash"u8, out var contentHashProperty)) { - fileRevision.ContentHash = jObject["contentHash"].ToObject(); + if(contentHashProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale contentHash property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ContentHash = contentHashProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - fileRevision.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - fileRevision.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale creator property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileRevision.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileRevision.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - fileRevision.FileType.AddRange(jObject["fileType"].ToOrderedItemCollection()); + fileRevision.FileType.AddRange(fileTypeProperty.ToOrderedItemCollection()); } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileRevision.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileRevision.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileRevision.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileRevision; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 79bc00a1f..743c58341 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileType = new CDP4Common.DTO.FileType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var fileType = new CDP4Common.DTO.FileType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - fileType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + fileType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - fileType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + fileType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - fileType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + fileType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["extension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("extension"u8, out var extensionProperty)) { - fileType.Extension = jObject["extension"].ToObject(); + if(extensionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale extension property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Extension = extensionProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - fileType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + fileType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - fileType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - fileType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index 7666608a3..a15b5febc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FolderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Folder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var folder = new CDP4Common.DTO.Folder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FolderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - folder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var folder = new CDP4Common.DTO.Folder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - folder.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + folder.ContainingFolder = null; + } + else + { + folder.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - folder.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - folder.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale creator property of the folder {id} is null", folder.Iid); + } + else + { + folder.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + folder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + folder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - folder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - folder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the folder {id} is null", folder.Iid); + } + else + { + folder.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - folder.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the folder {id} is null", folder.Iid); + } + else + { + folder.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - folder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the folder {id} is null", folder.Iid); + } + else + { + folder.ThingPreference = thingPreferenceProperty.GetString(); + } } return folder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 216ffe26c..0f233c960 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GlossaryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Glossary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var glossary = new CDP4Common.DTO.Glossary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GlossaryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - glossary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var glossary = new CDP4Common.DTO.Glossary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - glossary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + glossary.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - glossary.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + glossary.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - glossary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + glossary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + glossary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + glossary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - glossary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + glossary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - glossary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - glossary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - glossary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - glossary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - glossary.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + glossary.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - glossary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ThingPreference = thingPreferenceProperty.GetString(); + } } return glossary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index 49e10b6a9..be107d3a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GoalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Goal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var goal = new CDP4Common.DTO.Goal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GoalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - goal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var goal = new CDP4Common.DTO.Goal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - goal.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + goal.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - goal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + goal.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - goal.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + goal.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + goal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + goal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - goal.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + goal.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - goal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the goal {id} is null", goal.Iid); + } + else + { + goal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - goal.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the goal {id} is null", goal.Iid); + } + else + { + goal.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - goal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the goal {id} is null", goal.Iid); + } + else + { + goal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - goal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the goal {id} is null", goal.Iid); + } + else + { + goal.ThingPreference = thingPreferenceProperty.GetString(); + } } return goal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index c9aeb8e77..8b5405ded 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class HyperLinkResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.HyperLink FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var hyperLink = new CDP4Common.DTO.HyperLink(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the HyperLinkResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - hyperLink.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var hyperLink = new CDP4Common.DTO.HyperLink(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - hyperLink.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + hyperLink.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + hyperLink.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - hyperLink.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - hyperLink.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - hyperLink.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["uri"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("uri"u8, out var uriProperty)) { - hyperLink.Uri = jObject["uri"].ToObject(); + if(uriProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale uri property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Uri = uriProperty.GetString(); + } } return hyperLink; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index bbcebe19a..bcbf34af9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IdCorrespondenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IdCorrespondenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - idCorrespondence.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + idCorrespondence.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + idCorrespondence.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalId"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalId"u8, out var externalIdProperty)) { - idCorrespondence.ExternalId = jObject["externalId"].ToObject(); + if(externalIdProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalId property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ExternalId = externalIdProperty.GetString(); + } } - if (!jObject["internalThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("internalThing"u8, out var internalThingProperty)) { - idCorrespondence.InternalThing = jObject["internalThing"].ToObject(); + if(internalThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale internalThing property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.InternalThing = internalThingProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - idCorrespondence.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - idCorrespondence.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ThingPreference = thingPreferenceProperty.GetString(); + } } return idCorrespondence; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index bfb676f0b..ad3bd6f91 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IndependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IndependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - independentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - independentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + independentParameterTypeAssignment.MeasurementScale = null; + } + else + { + independentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - independentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - independentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - independentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return independentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index 7a18d3c5b..0dd94eb40 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IntervalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IntervalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var intervalScale = new CDP4Common.DTO.IntervalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IntervalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - intervalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var intervalScale = new CDP4Common.DTO.IntervalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + intervalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + intervalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + intervalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + intervalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - intervalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + intervalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - intervalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - intervalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - intervalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - intervalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + intervalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - intervalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - intervalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - intervalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - intervalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - intervalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - intervalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - intervalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - intervalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - intervalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - intervalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + intervalScale.ValueDefinition.Add(element.GetGuid()); + } } return intervalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index 61728e3fb..c98d0a973 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,161 +28,260 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Iteration FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iteration = new CDP4Common.DTO.Iteration(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iteration.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualFiniteStateList"].IsNullOrEmpty()) + var iteration = new CDP4Common.DTO.Iteration(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualFiniteStateList"u8, out var actualFiniteStateListProperty) && actualFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.ActualFiniteStateList.AddRange(jObject["actualFiniteStateList"].ToObject>()); + foreach(var element in actualFiniteStateListProperty.EnumerateArray()) + { + iteration.ActualFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["defaultOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOption"u8, out var defaultOptionProperty)) { - iteration.DefaultOption = jObject["defaultOption"].ToObject(); + if(defaultOptionProperty.ValueKind == JsonValueKind.Null) + { + iteration.DefaultOption = null; + } + else + { + iteration.DefaultOption = defaultOptionProperty.GetGuid(); + } } - if (!jObject["diagramCanvas"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramCanvas"u8, out var diagramCanvasProperty) && diagramCanvasProperty.ValueKind != JsonValueKind.Null) { - iteration.DiagramCanvas.AddRange(jObject["diagramCanvas"].ToObject>()); + foreach(var element in diagramCanvasProperty.EnumerateArray()) + { + iteration.DiagramCanvas.Add(element.GetGuid()); + } } - if (!jObject["domainFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainFileStore"u8, out var domainFileStoreProperty) && domainFileStoreProperty.ValueKind != JsonValueKind.Null) { - iteration.DomainFileStore.AddRange(jObject["domainFileStore"].ToObject>()); + foreach(var element in domainFileStoreProperty.EnumerateArray()) + { + iteration.DomainFileStore.Add(element.GetGuid()); + } } - if (!jObject["element"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("element"u8, out var elementProperty) && elementProperty.ValueKind != JsonValueKind.Null) { - iteration.Element.AddRange(jObject["element"].ToObject>()); + foreach(var element in elementProperty.EnumerateArray()) + { + iteration.Element.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iteration.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iteration.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalIdentifierMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalIdentifierMap"u8, out var externalIdentifierMapProperty) && externalIdentifierMapProperty.ValueKind != JsonValueKind.Null) { - iteration.ExternalIdentifierMap.AddRange(jObject["externalIdentifierMap"].ToObject>()); + foreach(var element in externalIdentifierMapProperty.EnumerateArray()) + { + iteration.ExternalIdentifierMap.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - iteration.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + iteration.Goal.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty)) { - iteration.IterationSetup = jObject["iterationSetup"].ToObject(); + if(iterationSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationSetup property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.IterationSetup = iterationSetupProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iteration.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["option"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("option"u8, out var optionProperty)) { - iteration.Option.AddRange(jObject["option"].ToOrderedItemCollection()); + iteration.Option.AddRange(optionProperty.ToOrderedItemCollection()); } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty) && possibleFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToObject>()); + foreach(var element in possibleFiniteStateListProperty.EnumerateArray()) + { + iteration.PossibleFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["publication"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publication"u8, out var publicationProperty) && publicationProperty.ValueKind != JsonValueKind.Null) { - iteration.Publication.AddRange(jObject["publication"].ToObject>()); + foreach(var element in publicationProperty.EnumerateArray()) + { + iteration.Publication.Add(element.GetGuid()); + } } - if (!jObject["relationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationship"u8, out var relationshipProperty) && relationshipProperty.ValueKind != JsonValueKind.Null) { - iteration.Relationship.AddRange(jObject["relationship"].ToObject>()); + foreach(var element in relationshipProperty.EnumerateArray()) + { + iteration.Relationship.Add(element.GetGuid()); + } } - if (!jObject["requirementsSpecification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirementsSpecification"u8, out var requirementsSpecificationProperty) && requirementsSpecificationProperty.ValueKind != JsonValueKind.Null) { - iteration.RequirementsSpecification.AddRange(jObject["requirementsSpecification"].ToObject>()); + foreach(var element in requirementsSpecificationProperty.EnumerateArray()) + { + iteration.RequirementsSpecification.Add(element.GetGuid()); + } } - if (!jObject["ruleVerificationList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerificationList"u8, out var ruleVerificationListProperty) && ruleVerificationListProperty.ValueKind != JsonValueKind.Null) { - iteration.RuleVerificationList.AddRange(jObject["ruleVerificationList"].ToObject>()); + foreach(var element in ruleVerificationListProperty.EnumerateArray()) + { + iteration.RuleVerificationList.Add(element.GetGuid()); + } } - if (!jObject["sharedDiagramStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedDiagramStyle"u8, out var sharedDiagramStyleProperty) && sharedDiagramStyleProperty.ValueKind != JsonValueKind.Null) { - iteration.SharedDiagramStyle.AddRange(jObject["sharedDiagramStyle"].ToObject>()); + foreach(var element in sharedDiagramStyleProperty.EnumerateArray()) + { + iteration.SharedDiagramStyle.Add(element.GetGuid()); + } } - if (!jObject["sourceIterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationIid"u8, out var sourceIterationIidProperty)) { - iteration.SourceIterationIid = jObject["sourceIterationIid"].ToObject(); + if(sourceIterationIidProperty.ValueKind == JsonValueKind.Null) + { + iteration.SourceIterationIid = null; + } + else + { + iteration.SourceIterationIid = sourceIterationIidProperty.GetGuid(); + } } - if (!jObject["stakeholder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholder"u8, out var stakeholderProperty) && stakeholderProperty.ValueKind != JsonValueKind.Null) { - iteration.Stakeholder.AddRange(jObject["stakeholder"].ToObject>()); + foreach(var element in stakeholderProperty.EnumerateArray()) + { + iteration.Stakeholder.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + iteration.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValueMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueMap"u8, out var stakeholderValueMapProperty) && stakeholderValueMapProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValueMap.AddRange(jObject["stakeholderValueMap"].ToObject>()); + foreach(var element in stakeholderValueMapProperty.EnumerateArray()) + { + iteration.StakeholderValueMap.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iteration.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topElement"u8, out var topElementProperty)) { - iteration.TopElement = jObject["topElement"].ToObject(); + if(topElementProperty.ValueKind == JsonValueKind.Null) + { + iteration.TopElement = null; + } + else + { + iteration.TopElement = topElementProperty.GetGuid(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - iteration.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + iteration.ValueGroup.Add(element.GetGuid()); + } } return iteration; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index acd9be70a..74109e6a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IterationSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iterationSetup = new CDP4Common.DTO.IterationSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iterationSetup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var iterationSetup = new CDP4Common.DTO.IterationSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - iterationSetup.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["description"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - iterationSetup.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale description property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iterationSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iterationSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["frozenOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("frozenOn"u8, out var frozenOnProperty)) { - iterationSetup.FrozenOn = jObject["frozenOn"].ToObject(); + if(frozenOnProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.FrozenOn = null; + } + else + { + iterationSetup.FrozenOn = frozenOnProperty.GetDateTime(); + } } - if (!jObject["isDeleted"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeleted"u8, out var isDeletedProperty)) { - iterationSetup.IsDeleted = jObject["isDeleted"].ToObject(); + if(isDeletedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeleted property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IsDeleted = isDeletedProperty.GetBoolean(); + } } - if (!jObject["iterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationIid"u8, out var iterationIidProperty)) { - iterationSetup.IterationIid = jObject["iterationIid"].ToObject(); + if(iterationIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationIid property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationIid = iterationIidProperty.GetGuid(); + } } - if (!jObject["iterationNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationNumber"u8, out var iterationNumberProperty)) { - iterationSetup.IterationNumber = jObject["iterationNumber"].ToObject(); + if(iterationNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationNumber property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationNumber = iterationNumberProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iterationSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["sourceIterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationSetup"u8, out var sourceIterationSetupProperty)) { - iterationSetup.SourceIterationSetup = jObject["sourceIterationSetup"].ToObject(); + if(sourceIterationSetupProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.SourceIterationSetup = null; + } + else + { + iterationSetup.SourceIterationSetup = sourceIterationSetupProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iterationSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return iterationSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index b94f3d8e0..5ec8444b6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LinearConversionUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LinearConversionUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - linearConversionUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + linearConversionUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - linearConversionUnit.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale conversionFactor property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + linearConversionUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + linearConversionUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - linearConversionUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - linearConversionUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - linearConversionUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.Name = nameProperty.GetString(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - linearConversionUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceUnit property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - linearConversionUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - linearConversionUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return linearConversionUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index 480ae3e55..797969a52 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,123 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogEntryChangelogItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogEntryChangelogItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logEntryChangelogItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty)) { - logEntryChangelogItem.AffectedItemIid = jObject["affectedItemIid"].ToObject(); + if(affectedItemIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale affectedItemIid property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.AffectedItemIid = affectedItemIidProperty.GetGuid(); + } } - if (!jObject["affectedReferenceIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedReferenceIid"u8, out var affectedReferenceIidProperty) && affectedReferenceIidProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.AffectedReferenceIid.AddRange(jObject["affectedReferenceIid"].ToObject>()); + foreach(var element in affectedReferenceIidProperty.EnumerateArray()) + { + logEntryChangelogItem.AffectedReferenceIid.Add(element.GetGuid()); + } } - if (!jObject["changeDescription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeDescription"u8, out var changeDescriptionProperty)) { - logEntryChangelogItem.ChangeDescription = jObject["changeDescription"].ToObject(); + if(changeDescriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeDescription property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangeDescription = changeDescriptionProperty.GetString(); + } } - if (!jObject["changelogKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changelogKind"u8, out var changelogKindProperty)) { - logEntryChangelogItem.ChangelogKind = jObject["changelogKind"].ToObject(); + if(changelogKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changelogKind property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangelogKind = LogEntryChangelogItemKindDeserializer.Deserialize(changelogKindProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logEntryChangelogItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logEntryChangelogItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return logEntryChangelogItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index 5af4cfd53..8b3a5e2d6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,161 +28,307 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogarithmicScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogarithmicScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logarithmicScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + logarithmicScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + logarithmicScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logarithmicScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logarithmicScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - logarithmicScale.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Exponent = exponentProperty.GetString(); + } } - if (!jObject["factor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("factor"u8, out var factorProperty)) { - logarithmicScale.Factor = jObject["factor"].ToObject(); + if(factorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale factor property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Factor = factorProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + logarithmicScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - logarithmicScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - logarithmicScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - logarithmicScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["logarithmBase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logarithmBase"u8, out var logarithmBaseProperty)) { - logarithmicScale.LogarithmBase = jObject["logarithmBase"].ToObject(); + if(logarithmBaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale logarithmBase property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.LogarithmBase = LogarithmBaseKindDeserializer.Deserialize(logarithmBaseProperty); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + logarithmicScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - logarithmicScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - logarithmicScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logarithmicScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - logarithmicScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - logarithmicScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - logarithmicScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - logarithmicScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["referenceQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityKind"u8, out var referenceQuantityKindProperty)) { - logarithmicScale.ReferenceQuantityKind = jObject["referenceQuantityKind"].ToObject(); + if(referenceQuantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceQuantityKind property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ReferenceQuantityKind = referenceQuantityKindProperty.GetGuid(); + } } - if (!jObject["referenceQuantityValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityValue"u8, out var referenceQuantityValueProperty) && referenceQuantityValueProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ReferenceQuantityValue.AddRange(jObject["referenceQuantityValue"].ToObject>()); + foreach(var element in referenceQuantityValueProperty.EnumerateArray()) + { + logarithmicScale.ReferenceQuantityValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - logarithmicScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logarithmicScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - logarithmicScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + logarithmicScale.ValueDefinition.Add(element.GetGuid()); + } } return logarithmicScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index c0c596590..e9ccb89b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MappingToReferenceScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MappingToReferenceScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - mappingToReferenceScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["dependentScaleValue"].IsNullOrEmpty()) + var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("dependentScaleValue"u8, out var dependentScaleValueProperty)) { - mappingToReferenceScale.DependentScaleValue = jObject["dependentScaleValue"].ToObject(); + if(dependentScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale dependentScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.DependentScaleValue = dependentScaleValueProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - mappingToReferenceScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referenceScaleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceScaleValue"u8, out var referenceScaleValueProperty)) { - mappingToReferenceScale.ReferenceScaleValue = jObject["referenceScaleValue"].ToObject(); + if(referenceScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ReferenceScaleValue = referenceScaleValueProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - mappingToReferenceScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ThingPreference = thingPreferenceProperty.GetString(); + } } return mappingToReferenceScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index 16a131cd2..b094b4c33 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,171 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - modelLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + modelLogEntry.Author = null; + } + else + { + modelLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + modelLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - modelLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - modelLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - modelLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - modelLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale level property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + modelLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return modelLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 6ed0e590d..30bd10fae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,146 +28,232 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - modelReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + modelReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + modelReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - modelReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - modelReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + modelReferenceDataLibrary.RequiredRdl = null; + } + else + { + modelReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - modelReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + modelReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return modelReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index b14060ed0..0be75fb8f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModellingThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModellingThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modellingThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modellingThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modellingThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modellingThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - modellingThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedRevisionNumber property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - modellingThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedThing property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modellingThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return modellingThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index b4f701b14..bb84b2ff0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + multiRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - multiRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + multiRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + multiRelationship.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index 1488aece5..f416dd9eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationshipRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + multiRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + multiRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + multiRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - multiRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxRelated"u8, out var maxRelatedProperty)) { - multiRelationshipRule.MaxRelated = jObject["maxRelated"].ToObject(); + if(maxRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maxRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MaxRelated = maxRelatedProperty.GetInt32(); + } } - if (!jObject["minRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minRelated"u8, out var minRelatedProperty)) { - multiRelationshipRule.MinRelated = jObject["minRelated"].ToObject(); + if(minRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MinRelated = minRelatedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationshipRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["relatedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedCategory"u8, out var relatedCategoryProperty) && relatedCategoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.RelatedCategory.AddRange(jObject["relatedCategory"].ToObject>()); + foreach(var element in relatedCategoryProperty.EnumerateArray()) + { + multiRelationshipRule.RelatedCategory.Add(element.GetGuid()); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - multiRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationshipCategory property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - multiRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index 1c30bd63b..faf8c2fca 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NaturalLanguageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NaturalLanguageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - naturalLanguage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + naturalLanguage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + naturalLanguage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - naturalLanguage.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - naturalLanguage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - naturalLanguage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.Name = nameProperty.GetString(); + } } - if (!jObject["nativeName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nativeName"u8, out var nativeNameProperty)) { - naturalLanguage.NativeName = jObject["nativeName"].ToObject(); + if(nativeNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale nativeName property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.NativeName = nativeNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - naturalLanguage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ThingPreference = thingPreferenceProperty.GetString(); + } } return naturalLanguage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index 2d06345ca..267e809bc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,116 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedElementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedElement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedElement = new CDP4Common.DTO.NestedElement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedElementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedElement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["elementUsage"].IsNullOrEmpty()) + var nestedElement = new CDP4Common.DTO.NestedElement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("elementUsage"u8, out var elementUsageProperty)) { - nestedElement.ElementUsage.AddRange(jObject["elementUsage"].ToOrderedItemCollection()); + nestedElement.ElementUsage.AddRange(elementUsageProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedElement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedElement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedElement.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isVolatile property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedElement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["nestedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedParameter"u8, out var nestedParameterProperty) && nestedParameterProperty.ValueKind != JsonValueKind.Null) { - nestedElement.NestedParameter.AddRange(jObject["nestedParameter"].ToObject>()); + foreach(var element in nestedParameterProperty.EnumerateArray()) + { + nestedElement.NestedParameter.Add(element.GetGuid()); + } } - if (!jObject["rootElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rootElement"u8, out var rootElementProperty)) { - nestedElement.RootElement = jObject["rootElement"].ToObject(); + if(rootElementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale rootElement property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.RootElement = rootElementProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedElement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedElement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index cbd235bf5..2598bdb4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedParameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedParameter = new CDP4Common.DTO.NestedParameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedParameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var nestedParameter = new CDP4Common.DTO.NestedParameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - nestedParameter.ActualState = jObject["actualState"].ToObject(); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + nestedParameter.ActualState = null; + } + else + { + nestedParameter.ActualState = actualStateProperty.GetGuid(); + } } - if (!jObject["actualValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualValue"u8, out var actualValueProperty)) { - nestedParameter.ActualValue = jObject["actualValue"].ToObject(); + if(actualValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale actualValue property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ActualValue = actualValueProperty.GetString(); + } } - if (!jObject["associatedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("associatedParameter"u8, out var associatedParameterProperty)) { - nestedParameter.AssociatedParameter = jObject["associatedParameter"].ToObject(); + if(associatedParameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale associatedParameter property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.AssociatedParameter = associatedParameterProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedParameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedParameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - nestedParameter.Formula = jObject["formula"].ToObject(); + if(formulaProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale formula property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Formula = formulaProperty.GetString(); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedParameter.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isVolatile property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedParameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - nestedParameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedParameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedParameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index aed83415d..ced4ee8de 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,91 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NotExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NotExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var notExpression = new CDP4Common.DTO.NotExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NotExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - notExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var notExpression = new CDP4Common.DTO.NotExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + notExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + notExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - notExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty)) { - notExpression.Term = jObject["term"].ToObject(); + if(termProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale term property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.Term = termProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - notExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return notExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index 11e136c9a..37f545056 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Option FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var option = new CDP4Common.DTO.Option(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - option.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var option = new CDP4Common.DTO.Option(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - option.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + option.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - option.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + option.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - option.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + option.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + option.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + option.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - option.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + option.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - option.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the option {id} is null", option.Iid); + } + else + { + option.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - option.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the option {id} is null", option.Iid); + } + else + { + option.Name = nameProperty.GetString(); + } } - if (!jObject["nestedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedElement"u8, out var nestedElementProperty) && nestedElementProperty.ValueKind != JsonValueKind.Null) { - option.NestedElement.AddRange(jObject["nestedElement"].ToObject>()); + foreach(var element in nestedElementProperty.EnumerateArray()) + { + option.NestedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - option.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the option {id} is null", option.Iid); + } + else + { + option.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - option.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the option {id} is null", option.Iid); + } + else + { + option.ThingPreference = thingPreferenceProperty.GetString(); + } } return option; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index b6a513532..a6c5e29a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,87 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var orExpression = new CDP4Common.DTO.OrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - orExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var orExpression = new CDP4Common.DTO.OrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + orExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + orExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - orExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - orExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + orExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - orExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return orExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index d4361272f..28e6d26b5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,263 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrdinalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrdinalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrdinalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ordinalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ordinalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ordinalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ordinalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ordinalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ordinalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ordinalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ordinalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ordinalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ordinalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ordinalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ordinalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ordinalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ordinalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ordinalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ordinalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ordinalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ordinalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ordinalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ordinalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["useShortNameValues"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("useShortNameValues"u8, out var useShortNameValuesProperty)) { - ordinalScale.UseShortNameValues = jObject["useShortNameValues"].ToObject(); + if(useShortNameValuesProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale useShortNameValues property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.UseShortNameValues = useShortNameValuesProperty.GetBoolean(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ordinalScale.ValueDefinition.Add(element.GetGuid()); + } } return ordinalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index 2b6c03580..2212bddfd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Organization FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organization = new CDP4Common.DTO.Organization(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organization.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organization = new CDP4Common.DTO.Organization(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organization.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organization.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - organization.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the organization {id} is null", organization.Iid); + } + else + { + organization.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organization.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the organization {id} is null", organization.Iid); + } + else + { + organization.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - organization.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the organization {id} is null", organization.Iid); + } + else + { + organization.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - organization.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the organization {id} is null", organization.Iid); + } + else + { + organization.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organization.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the organization {id} is null", organization.Iid); + } + else + { + organization.ThingPreference = thingPreferenceProperty.GetString(); + } } return organization; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index cc457aa9b..a477bc0d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,91 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationalParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationalParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organizationalParticipant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organizationalParticipant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - organizationalParticipant.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale organization property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organizationalParticipant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ThingPreference = thingPreferenceProperty.GetString(); + } } return organizationalParticipant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index ce85879f0..c4c58cb19 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,243 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OwnedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OwnedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OwnedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ownedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ownedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ownedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - ownedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillColor = null; + } + else + { + ownedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - ownedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillOpacity = null; + } + else + { + ownedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - ownedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontBold = null; + } + else + { + ownedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - ownedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontColor = null; + } + else + { + ownedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - ownedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontItalic = null; + } + else + { + ownedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - ownedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fontName property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - ownedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontSize = null; + } + else + { + ownedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - ownedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontStrokeThrough = null; + } + else + { + ownedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - ownedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontUnderline = null; + } + else + { + ownedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ownedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ownedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - ownedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeColor = null; + } + else + { + ownedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - ownedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeOpacity = null; + } + else + { + ownedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - ownedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeWidth = null; + } + else + { + ownedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ownedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + ownedStyle.UsedColor.Add(element.GetGuid()); + } } return ownedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index dc9da33cc..8e660d4c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Page FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var page = new CDP4Common.DTO.Page(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - page.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var page = new CDP4Common.DTO.Page(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - page.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + page.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - page.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the page {id} is null", page.Iid); + } + else + { + page.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + page.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + page.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - page.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the page {id} is null", page.Iid); + } + else + { + page.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - page.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the page {id} is null", page.Iid); + } + else + { + page.Name = nameProperty.GetString(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - page.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + page.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - page.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the page {id} is null", page.Iid); + } + else + { + page.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - page.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the page {id} is null", page.Iid); + } + else + { + page.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - page.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the page {id} is null", page.Iid); + } + else + { + page.ThingPreference = thingPreferenceProperty.GetString(); + } } return page; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 33a7e1b0d..464ab4ccd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingGroup"].IsNullOrEmpty()) + var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingGroup"u8, out var containingGroupProperty)) { - parameterGroup.ContainingGroup = jObject["containingGroup"].ToObject(); + if(containingGroupProperty.ValueKind == JsonValueKind.Null) + { + parameterGroup.ContainingGroup = null; + } + else + { + parameterGroup.ContainingGroup = containingGroupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index dbef7ca82..581450bb9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverride FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverride.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverride.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverride.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverride.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterOverride.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty)) { - parameterOverride.Parameter = jObject["parameter"].ToObject(); + if(parameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameter property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Parameter = parameterProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameterOverride.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverride.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterOverride.ValueSet.Add(element.GetGuid()); + } } return parameterOverride; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index f03080fa1..24b52b639 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,124 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterOverrideValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterOverrideValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterOverrideValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["parameterValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverrideValueSet.ParameterValueSet = jObject["parameterValueSet"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValueSet"u8, out var parameterValueSetProperty)) { - parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(parameterValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterValueSet property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ParameterValueSet = parameterValueSetProperty.GetGuid(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverrideValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterOverrideValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterOverrideValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index b1322dfc7..8c6f0d9a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,203 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Parameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameter = new CDP4Common.DTO.Parameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["allowDifferentOwnerOfOverride"].IsNullOrEmpty()) + var parameter = new CDP4Common.DTO.Parameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("allowDifferentOwnerOfOverride"u8, out var allowDifferentOwnerOfOverrideProperty)) { - parameter.AllowDifferentOwnerOfOverride = jObject["allowDifferentOwnerOfOverride"].ToObject(); + if(allowDifferentOwnerOfOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale allowDifferentOwnerOfOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.AllowDifferentOwnerOfOverride = allowDifferentOwnerOfOverrideProperty.GetBoolean(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expectsOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expectsOverride"u8, out var expectsOverrideProperty)) { - parameter.ExpectsOverride = jObject["expectsOverride"].ToObject(); + if(expectsOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale expectsOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ExpectsOverride = expectsOverrideProperty.GetBoolean(); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - parameter.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + parameter.Group = null; + } + else + { + parameter.Group = groupProperty.GetGuid(); + } } - if (!jObject["isOptionDependent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isOptionDependent"u8, out var isOptionDependentProperty)) { - parameter.IsOptionDependent = jObject["isOptionDependent"].ToObject(); + if(isOptionDependentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isOptionDependent property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.IsOptionDependent = isOptionDependentProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameter.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameter.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameter.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["requestedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requestedBy"u8, out var requestedByProperty)) { - parameter.RequestedBy = jObject["requestedBy"].ToObject(); + if(requestedByProperty.ValueKind == JsonValueKind.Null) + { + parameter.RequestedBy = null; + } + else + { + parameter.RequestedBy = requestedByProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameter.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameter.Scale = null; + } + else + { + parameter.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["stateDependence"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stateDependence"u8, out var stateDependenceProperty)) { - parameter.StateDependence = jObject["stateDependence"].ToObject(); + if(stateDependenceProperty.ValueKind == JsonValueKind.Null) + { + parameter.StateDependence = null; + } + else + { + parameter.StateDependence = stateDependenceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameter.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameter.ValueSet.Add(element.GetGuid()); + } } return parameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index 73cba783c..7ed54fe41 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscription.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscription.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscription.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscription.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterSubscription.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscription.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterSubscription.ValueSet.Add(element.GetGuid()); + } } return parameterSubscription; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index be56c333b..07a280703 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterSubscriptionValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscriptionValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscriptionValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) + { + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedPerson.Add(element.GetGuid()); + } + } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscriptionValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["subscribedValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("subscribedValueSet"u8, out var subscribedValueSetProperty)) { - parameterSubscriptionValueSet.SubscribedValueSet = jObject["subscribedValueSet"].ToObject(); + if(subscribedValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale subscribedValueSet property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.SubscribedValueSet = subscribedValueSetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscriptionValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterSubscriptionValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterSubscriptionValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index 4702a193d..8223b6a2f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterTypeComponentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterTypeComponentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterTypeComponent.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterTypeComponent.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameterTypeComponent.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameterTypeComponent.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameterTypeComponent.Scale = null; + } + else + { + parameterTypeComponent.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterTypeComponent.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterTypeComponent.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterTypeComponent; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index 9d6770045..045a68a19 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["actualOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterValueSet.ActualOption = jObject["actualOption"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualOption"u8, out var actualOptionProperty)) { - parameterValueSet.ActualState = jObject["actualState"].ToObject(); + if(actualOptionProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualOption = null; + } + else + { + parameterValueSet.ActualOption = actualOptionProperty.GetGuid(); + } } - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - parameterValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualState = null; + } + else + { + parameterValueSet.ActualState = actualStateProperty.GetGuid(); + } } - - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + parameterValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + parameterValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + parameterValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index d700d006a..dd07a654d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterizedCategoryRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterizedCategoryRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterizedCategoryRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + parameterizedCategoryRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty)) { - parameterizedCategoryRule.Category = jObject["category"].ToObject(); + if(categoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale category property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Category = categoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + parameterizedCategoryRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + parameterizedCategoryRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - parameterizedCategoryRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterizedCategoryRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterizedCategoryRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + parameterizedCategoryRule.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterizedCategoryRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterizedCategoryRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterizedCategoryRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index 67140eb4c..0a2167b1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParametricConstraintResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParametricConstraintResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parametricConstraint.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parametricConstraint.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parametricConstraint.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expression"u8, out var expressionProperty) && expressionProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.Expression.AddRange(jObject["expression"].ToObject>()); + foreach(var element in expressionProperty.EnumerateArray()) + { + parametricConstraint.Expression.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parametricConstraint.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parametricConstraint.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topExpression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topExpression"u8, out var topExpressionProperty)) { - parametricConstraint.TopExpression = jObject["topExpression"].ToObject(); + if(topExpressionProperty.ValueKind == JsonValueKind.Null) + { + parametricConstraint.TopExpression = null; + } + else + { + parametricConstraint.TopExpression = topExpressionProperty.GetGuid(); + } } return parametricConstraint; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index d116aee28..c2339f659 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - participantPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale accessRight property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.AccessRight = ParticipantAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - participantPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale objectClass property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index 45113f2bb..ae2e97390 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Participant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participant = new CDP4Common.DTO.Participant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["domain"].IsNullOrEmpty()) + var participant = new CDP4Common.DTO.Participant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - participant.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + participant.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - participant.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the participant {id} is null", participant.Iid); + } + else + { + participant.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participant {id} is null", participant.Iid); + } + else + { + participant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty)) { - participant.Person = jObject["person"].ToObject(); + if(personProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale person property of the participant {id} is null", participant.Iid); + } + else + { + participant.Person = personProperty.GetGuid(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - participant.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale role property of the participant {id} is null", participant.Iid); + } + else + { + participant.Role = roleProperty.GetGuid(); + } } - if (!jObject["selectedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("selectedDomain"u8, out var selectedDomainProperty)) { - participant.SelectedDomain = jObject["selectedDomain"].ToObject(); + if(selectedDomainProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale selectedDomain property of the participant {id} is null", participant.Iid); + } + else + { + participant.SelectedDomain = selectedDomainProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participant {id} is null", participant.Iid); + } + else + { + participant.ThingPreference = thingPreferenceProperty.GetString(); + } } return participant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index 27ba6921c..dc98a81ec 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantRole = new CDP4Common.DTO.ParticipantRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var participantRole = new CDP4Common.DTO.ParticipantRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - participantRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + participantRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - participantRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + participantRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - participantRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + participantRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - participantRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.Name = nameProperty.GetString(); + } } - if (!jObject["participantPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantPermission"u8, out var participantPermissionProperty) && participantPermissionProperty.ValueKind != JsonValueKind.Null) { - participantRole.ParticipantPermission.AddRange(jObject["participantPermission"].ToObject>()); + foreach(var element in participantPermissionProperty.EnumerateArray()) + { + participantRole.ParticipantPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - participantRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index 55a189b68..4319167f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personPermission = new CDP4Common.DTO.PersonPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var personPermission = new CDP4Common.DTO.PersonPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - personPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale accessRight property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.AccessRight = PersonAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - personPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale objectClass property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return personPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index 49e6895de..286a55dd9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,247 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Person FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var person = new CDP4Common.DTO.Person(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - person.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["defaultDomain"].IsNullOrEmpty()) + var person = new CDP4Common.DTO.Person(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("defaultDomain"u8, out var defaultDomainProperty)) { - person.DefaultDomain = jObject["defaultDomain"].ToObject(); + if(defaultDomainProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultDomain = null; + } + else + { + person.DefaultDomain = defaultDomainProperty.GetGuid(); + } } - if (!jObject["defaultEmailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultEmailAddress"u8, out var defaultEmailAddressProperty)) { - person.DefaultEmailAddress = jObject["defaultEmailAddress"].ToObject(); + if(defaultEmailAddressProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultEmailAddress = null; + } + else + { + person.DefaultEmailAddress = defaultEmailAddressProperty.GetGuid(); + } } - if (!jObject["defaultTelephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultTelephoneNumber"u8, out var defaultTelephoneNumberProperty)) { - person.DefaultTelephoneNumber = jObject["defaultTelephoneNumber"].ToObject(); + if(defaultTelephoneNumberProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultTelephoneNumber = null; + } + else + { + person.DefaultTelephoneNumber = defaultTelephoneNumberProperty.GetGuid(); + } } - if (!jObject["emailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("emailAddress"u8, out var emailAddressProperty) && emailAddressProperty.ValueKind != JsonValueKind.Null) { - person.EmailAddress.AddRange(jObject["emailAddress"].ToObject>()); + foreach(var element in emailAddressProperty.EnumerateArray()) + { + person.EmailAddress.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + person.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + person.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["givenName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("givenName"u8, out var givenNameProperty)) { - person.GivenName = jObject["givenName"].ToObject(); + if(givenNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale givenName property of the person {id} is null", person.Iid); + } + else + { + person.GivenName = givenNameProperty.GetString(); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - person.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the person {id} is null", person.Iid); + } + else + { + person.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - person.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the person {id} is null", person.Iid); + } + else + { + person.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - person.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the person {id} is null", person.Iid); + } + else + { + person.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - person.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + person.Organization = null; + } + else + { + person.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["organizationalUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalUnit"u8, out var organizationalUnitProperty)) { - person.OrganizationalUnit = jObject["organizationalUnit"].ToObject(); + if(organizationalUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale organizationalUnit property of the person {id} is null", person.Iid); + } + else + { + person.OrganizationalUnit = organizationalUnitProperty.GetString(); + } } - if (!jObject["password"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("password"u8, out var passwordProperty)) { - person.Password = jObject["password"].ToObject(); + if(passwordProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale password property of the person {id} is null", person.Iid); + } + else + { + person.Password = passwordProperty.GetString(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - person.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + person.Role = null; + } + else + { + person.Role = roleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - person.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the person {id} is null", person.Iid); + } + else + { + person.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["surname"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("surname"u8, out var surnameProperty)) { - person.Surname = jObject["surname"].ToObject(); + if(surnameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale surname property of the person {id} is null", person.Iid); + } + else + { + person.Surname = surnameProperty.GetString(); + } } - if (!jObject["telephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("telephoneNumber"u8, out var telephoneNumberProperty) && telephoneNumberProperty.ValueKind != JsonValueKind.Null) { - person.TelephoneNumber.AddRange(jObject["telephoneNumber"].ToObject>()); + foreach(var element in telephoneNumberProperty.EnumerateArray()) + { + person.TelephoneNumber.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - person.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the person {id} is null", person.Iid); + } + else + { + person.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["userPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("userPreference"u8, out var userPreferenceProperty) && userPreferenceProperty.ValueKind != JsonValueKind.Null) { - person.UserPreference.AddRange(jObject["userPreference"].ToObject>()); + foreach(var element in userPreferenceProperty.EnumerateArray()) + { + person.UserPreference.Add(element.GetGuid()); + } } return person; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index 9ec5daba8..41661b8bf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personRole = new CDP4Common.DTO.PersonRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var personRole = new CDP4Common.DTO.PersonRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - personRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + personRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - personRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + personRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - personRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + personRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - personRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.Name = nameProperty.GetString(); + } } - if (!jObject["personPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personPermission"u8, out var personPermissionProperty) && personPermissionProperty.ValueKind != JsonValueKind.Null) { - personRole.PersonPermission.AddRange(jObject["personPermission"].ToObject>()); + foreach(var element in personPermissionProperty.EnumerateArray()) + { + personRole.PersonPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - personRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return personRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index 44cacac81..cbe6fc2ac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PointResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Point FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var point = new CDP4Common.DTO.Point(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PointResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - point.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var point = new CDP4Common.DTO.Point(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + point.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + point.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - point.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the point {id} is null", point.Iid); + } + else + { + point.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - point.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the point {id} is null", point.Iid); + } + else + { + point.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - point.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the point {id} is null", point.Iid); + } + else + { + point.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - point.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale x property of the point {id} is null", point.Iid); + } + else + { + point.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - point.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale y property of the point {id} is null", point.Iid); + } + else + { + point.Y = yProperty.GetSingle(); + } } return point; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index 7172ea9ea..e512c0dcb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,164 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteStateList.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + possibleFiniteStateList.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultState"u8, out var defaultStateProperty)) { - possibleFiniteStateList.DefaultState = jObject["defaultState"].ToObject(); + if(defaultStateProperty.ValueKind == JsonValueKind.Null) + { + possibleFiniteStateList.DefaultState = null; + } + else + { + possibleFiniteStateList.DefaultState = defaultStateProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteStateList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteStateList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteStateList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - possibleFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty)) { - possibleFiniteStateList.PossibleState.AddRange(jObject["possibleState"].ToOrderedItemCollection()); + possibleFiniteStateList.PossibleState.AddRange(possibleStateProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteStateList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index a381d03d8..11535ae6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteState.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteState.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteState.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteState.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteState.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index c5eb961c8..839c14026 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PrefixedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PrefixedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - prefixedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + prefixedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + prefixedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + prefixedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + prefixedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + prefixedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - prefixedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - prefixedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["prefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("prefix"u8, out var prefixProperty)) { - prefixedUnit.Prefix = jObject["prefix"].ToObject(); + if(prefixProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale prefix property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.Prefix = prefixProperty.GetGuid(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - prefixedUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceUnit property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - prefixedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return prefixedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index 84ebf4f51..d72f4da56 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PublicationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Publication FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var publication = new CDP4Common.DTO.Publication(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PublicationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - publication.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var publication = new CDP4Common.DTO.Publication(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - publication.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - publication.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + publication.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + publication.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + publication.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - publication.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["publishedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedParameter"u8, out var publishedParameterProperty) && publishedParameterProperty.ValueKind != JsonValueKind.Null) { - publication.PublishedParameter.AddRange(jObject["publishedParameter"].ToObject>()); + foreach(var element in publishedParameterProperty.EnumerateArray()) + { + publication.PublishedParameter.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - publication.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the publication {id} is null", publication.Iid); + } + else + { + publication.ThingPreference = thingPreferenceProperty.GetString(); + } } return publication; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index 0997ef62d..089263793 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class QuantityKindFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the QuantityKindFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - quantityKindFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - quantityKindFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - quantityKindFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["quantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKind"u8, out var quantityKindProperty)) { - quantityKindFactor.QuantityKind = jObject["quantityKind"].ToObject(); + if(quantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityKind property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.QuantityKind = quantityKindProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - quantityKindFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } return quantityKindFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 5dd7af283..7cf7008c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,251 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ratioScale = new CDP4Common.DTO.RatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ratioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ratioScale = new CDP4Common.DTO.RatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ratioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ratioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ratioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ratioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ratioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ratioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ratioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ratioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ratioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ratioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ratioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ratioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ratioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ratioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ratioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ratioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ratioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ratioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ratioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ratioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ratioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ratioScale.ValueDefinition.Add(element.GetGuid()); + } } return ratioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index 75cfcb127..b32c08056 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,231 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferenceSourceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferenceSource FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referenceSource = new CDP4Common.DTO.ReferenceSource(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferenceSourceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referenceSource.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referenceSource = new CDP4Common.DTO.ReferenceSource(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referenceSource.Alias.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - referenceSource.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Author = authorProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + referenceSource.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referenceSource.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referenceSource.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referenceSource.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referenceSource.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referenceSource.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referenceSource.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["language"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("language"u8, out var languageProperty)) { - referenceSource.Language = jObject["language"].ToObject(); + if(languageProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale language property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Language = languageProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referenceSource.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referenceSource.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Name = nameProperty.GetString(); + } } - if (!jObject["publicationYear"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publicationYear"u8, out var publicationYearProperty)) { - referenceSource.PublicationYear = jObject["publicationYear"].ToObject(); + if(publicationYearProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublicationYear = null; + } + else + { + referenceSource.PublicationYear = publicationYearProperty.GetInt32(); + } } - if (!jObject["publishedIn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedIn"u8, out var publishedInProperty)) { - referenceSource.PublishedIn = jObject["publishedIn"].ToObject(); + if(publishedInProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublishedIn = null; + } + else + { + referenceSource.PublishedIn = publishedInProperty.GetGuid(); + } } - if (!jObject["publisher"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publisher"u8, out var publisherProperty)) { - referenceSource.Publisher = jObject["publisher"].ToObject(); + if(publisherProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.Publisher = null; + } + else + { + referenceSource.Publisher = publisherProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referenceSource.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referenceSource.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["versionDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionDate"u8, out var versionDateProperty)) { - referenceSource.VersionDate = jObject["versionDate"].ToObject(); + if(versionDateProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.VersionDate = null; + } + else + { + referenceSource.VersionDate = versionDateProperty.GetDateTime(); + } } - if (!jObject["versionIdentifier"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionIdentifier"u8, out var versionIdentifierProperty)) { - referenceSource.VersionIdentifier = jObject["versionIdentifier"].ToObject(); + if(versionIdentifierProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale versionIdentifier property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.VersionIdentifier = versionIdentifierProperty.GetString(); + } } return referenceSource; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index b2e36e75f..fc0f56672 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferencerRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferencerRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referencerRule = new CDP4Common.DTO.ReferencerRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferencerRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referencerRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referencerRule = new CDP4Common.DTO.ReferencerRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referencerRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referencerRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referencerRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referencerRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referencerRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referencerRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referencerRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxReferenced"u8, out var maxReferencedProperty)) { - referencerRule.MaxReferenced = jObject["maxReferenced"].ToObject(); + if(maxReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maxReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MaxReferenced = maxReferencedProperty.GetInt32(); + } } - if (!jObject["minReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minReferenced"u8, out var minReferencedProperty)) { - referencerRule.MinReferenced = jObject["minReferenced"].ToObject(); + if(minReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MinReferenced = minReferencedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referencerRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referencerRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.Name = nameProperty.GetString(); + } } - if (!jObject["referencedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedCategory"u8, out var referencedCategoryProperty) && referencedCategoryProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ReferencedCategory.AddRange(jObject["referencedCategory"].ToObject>()); + foreach(var element in referencedCategoryProperty.EnumerateArray()) + { + referencerRule.ReferencedCategory.Add(element.GetGuid()); + } } - if (!jObject["referencingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencingCategory"u8, out var referencingCategoryProperty)) { - referencerRule.ReferencingCategory = jObject["referencingCategory"].ToObject(); + if(referencingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencingCategory property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ReferencingCategory = referencingCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referencerRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referencerRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return referencerRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index 08282a325..ca549cad2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationalExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationalExpression FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationalExpression.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationalExpressionResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationalExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationalExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationalExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationalExpression.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationalOperator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationalExpression.RelationalOperator = jObject["relationalOperator"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationalOperator"u8, out var relationalOperatorProperty)) { - relationalExpression.Scale = jObject["scale"].ToObject(); + if(relationalOperatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationalOperator property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.RelationalOperator = RelationalOperatorKindDeserializer.Deserialize(relationalOperatorProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationalExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationalExpression.Scale = null; + } + else + { + relationalExpression.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationalExpression.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + relationalExpression.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return relationalExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index e53d645a3..65c5f9236 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationshipParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationshipParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationshipParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationshipParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationshipParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationshipParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationshipParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationshipParameterValue.Scale = null; + } + else + { + relationshipParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationshipParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + relationshipParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return relationshipParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index 7bb113a57..e3f87ec31 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForDeviationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForDeviationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForDeviation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForDeviation.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForDeviation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForDeviation.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForDeviation.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForDeviation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForDeviation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForDeviation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForDeviation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForDeviation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForDeviation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForDeviation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForDeviation.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForDeviation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForDeviation.PrimaryAnnotatedThing = null; + } + else + { + requestForDeviation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForDeviation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForDeviation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForDeviation.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForDeviation.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForDeviation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForDeviation.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Title = titleProperty.GetString(); + } } return requestForDeviation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index b8e642cd2..a56451c6b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForWaiverResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForWaiverResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForWaiver.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForWaiver.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForWaiver.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForWaiver.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForWaiver.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForWaiver.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForWaiver.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForWaiver.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForWaiver.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForWaiver.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForWaiver.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForWaiver.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForWaiver.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForWaiver.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForWaiver.PrimaryAnnotatedThing = null; + } + else + { + requestForWaiver.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForWaiver.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForWaiver.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForWaiver.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForWaiver.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForWaiver.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForWaiver.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Title = titleProperty.GetString(); + } } return requestForWaiver; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index 06b574a11..2d7adbcde 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,184 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Requirement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirement = new CDP4Common.DTO.Requirement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirement = new CDP4Common.DTO.Requirement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirement.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirement.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirement.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirement.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirement.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirement.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - requirement.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + requirement.Group = null; + } + else + { + requirement.Group = groupProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirement.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirement.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirement.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirement.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirement.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirement.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirement.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["parametricConstraint"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parametricConstraint"u8, out var parametricConstraintProperty)) { - requirement.ParametricConstraint.AddRange(jObject["parametricConstraint"].ToOrderedItemCollection()); + requirement.ParametricConstraint.AddRange(parametricConstraintProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirement.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index 2a9b998fd..4fbdf07aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsContainerParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - requirementsContainerParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsContainerParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsContainerParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsContainerParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - requirementsContainerParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - requirementsContainerParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + requirementsContainerParameterValue.Scale = null; + } + else + { + requirementsContainerParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return requirementsContainerParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index ab333a3b0..1439abe7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,163 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsGroup.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsGroup.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsGroup.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index 5b8809297..c6cb5b0c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,183 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsSpecificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsSpecificationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsSpecification.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsSpecification.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsSpecification.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsSpecification.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsSpecification.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsSpecification.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirementsSpecification.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsSpecification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsSpecification.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsSpecification.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsSpecification.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + requirementsSpecification.Requirement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsSpecification.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsSpecification.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsSpecification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index 57a009935..163e50852 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,247 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReviewItemDiscrepancyResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReviewItemDiscrepancyResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - reviewItemDiscrepancy.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - reviewItemDiscrepancy.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - reviewItemDiscrepancy.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - reviewItemDiscrepancy.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - reviewItemDiscrepancy.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - reviewItemDiscrepancy.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - reviewItemDiscrepancy.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - reviewItemDiscrepancy.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - reviewItemDiscrepancy.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = null; + } + else + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + reviewItemDiscrepancy.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - reviewItemDiscrepancy.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["solution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("solution"u8, out var solutionProperty) && solutionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Solution.AddRange(jObject["solution"].ToObject>()); + foreach(var element in solutionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Solution.Add(element.GetGuid()); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + reviewItemDiscrepancy.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - reviewItemDiscrepancy.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - reviewItemDiscrepancy.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - reviewItemDiscrepancy.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Title = titleProperty.GetString(); + } } return reviewItemDiscrepancy; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index ac0a0809d..2d970f525 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,144 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleVerificationListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleVerificationListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleVerificationList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ruleVerificationList.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ruleVerificationList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ruleVerificationList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleVerificationList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ruleVerificationList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - ruleVerificationList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["ruleVerification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerification"u8, out var ruleVerificationProperty)) { - ruleVerificationList.RuleVerification.AddRange(jObject["ruleVerification"].ToOrderedItemCollection()); + ruleVerificationList.RuleVerification.AddRange(ruleVerificationProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ruleVerificationList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleVerificationList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ThingPreference = thingPreferenceProperty.GetString(); + } } return ruleVerificationList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index 9ba38c9ff..45a79e1df 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleViolationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleViolation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleViolation = new CDP4Common.DTO.RuleViolation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleViolationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleViolation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["description"].IsNullOrEmpty()) + var ruleViolation = new CDP4Common.DTO.RuleViolation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - ruleViolation.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale description property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleViolation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleViolation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleViolation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleViolation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["violatingThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("violatingThing"u8, out var violatingThingProperty) && violatingThingProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ViolatingThing.AddRange(jObject["violatingThing"].ToObject>()); + foreach(var element in violatingThingProperty.EnumerateArray()) + { + ruleViolation.ViolatingThing.Add(element.GetGuid()); + } } return ruleViolation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index 5fc183341..946660f7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,185 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SampledFunctionParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - sampledFunctionParameterType.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SampledFunctionParameterTypeResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sampledFunctionParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + sampledFunctionParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + sampledFunctionParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["degreeOfInterpolation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.DegreeOfInterpolation = jObject["degreeOfInterpolation"].ToObject(); + foreach(var element in definitionProperty.EnumerateArray()) + { + sampledFunctionParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dependentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("degreeOfInterpolation"u8, out var degreeOfInterpolationProperty)) { - sampledFunctionParameterType.DependentParameterType.AddRange(jObject["dependentParameterType"].ToOrderedItemCollection()); + if(degreeOfInterpolationProperty.ValueKind == JsonValueKind.Null) + { + sampledFunctionParameterType.DegreeOfInterpolation = null; + } + else + { + sampledFunctionParameterType.DegreeOfInterpolation = degreeOfInterpolationProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dependentParameterType"u8, out var dependentParameterTypeProperty)) { - sampledFunctionParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + sampledFunctionParameterType.DependentParameterType.AddRange(dependentParameterTypeProperty.ToOrderedItemCollection()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["independentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.IndependentParameterType.AddRange(jObject["independentParameterType"].ToOrderedItemCollection()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + sampledFunctionParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interpolationPeriod"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("independentParameterType"u8, out var independentParameterTypeProperty)) + { + sampledFunctionParameterType.IndependentParameterType.AddRange(independentParameterTypeProperty.ToOrderedItemCollection()); + } + if (jsonElement.TryGetProperty("interpolationPeriod"u8, out var interpolationPeriodProperty)) { - sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(jObject["interpolationPeriod"].ToString()); + sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(interpolationPeriodProperty.GetString()); } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - sampledFunctionParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sampledFunctionParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sampledFunctionParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - sampledFunctionParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - sampledFunctionParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sampledFunctionParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return sampledFunctionParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index c174b94af..4b915e1f5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleReferenceQuantityValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleReferenceQuantityValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleReferenceQuantityValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleReferenceQuantityValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - scaleReferenceQuantityValue.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale scale property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleReferenceQuantityValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleReferenceQuantityValue.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Value = valueProperty.GetString(); + } } return scaleReferenceQuantityValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index ea7fb849c..819ab270f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + scaleValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + scaleValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + scaleValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - scaleValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - scaleValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleValueDefinition.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Value = valueProperty.GetString(); + } } return scaleValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index 326050662..9fc4e315c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,140 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SectionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Section FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var section = new CDP4Common.DTO.Section(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SectionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - section.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var section = new CDP4Common.DTO.Section(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - section.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + section.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - section.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the section {id} is null", section.Iid); + } + else + { + section.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + section.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + section.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - section.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the section {id} is null", section.Iid); + } + else + { + section.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - section.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the section {id} is null", section.Iid); + } + else + { + section.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - section.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the section {id} is null", section.Iid); + } + else + { + section.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["page"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("page"u8, out var pageProperty)) { - section.Page.AddRange(jObject["page"].ToOrderedItemCollection()); + section.Page.AddRange(pageProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - section.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the section {id} is null", section.Iid); + } + else + { + section.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - section.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the section {id} is null", section.Iid); + } + else + { + section.ThingPreference = thingPreferenceProperty.GetString(); + } } return section; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index c027c93b0..cfa19318a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,243 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SharedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SharedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sharedStyle = new CDP4Common.DTO.SharedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SharedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sharedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var sharedStyle = new CDP4Common.DTO.SharedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sharedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sharedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - sharedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillColor = null; + } + else + { + sharedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - sharedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillOpacity = null; + } + else + { + sharedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - sharedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontBold = null; + } + else + { + sharedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - sharedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontColor = null; + } + else + { + sharedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - sharedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontItalic = null; + } + else + { + sharedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - sharedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fontName property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - sharedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontSize = null; + } + else + { + sharedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - sharedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontStrokeThrough = null; + } + else + { + sharedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - sharedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontUnderline = null; + } + else + { + sharedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sharedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sharedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - sharedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeColor = null; + } + else + { + sharedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - sharedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeOpacity = null; + } + else + { + sharedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - sharedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeWidth = null; + } + else + { + sharedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sharedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + sharedStyle.UsedColor.Add(element.GetGuid()); + } } return sharedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index 0dce0d358..fa8f3b82c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,107 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - simpleParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SimpleParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - simpleParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - simpleParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + simpleParameterValue.Scale = null; + } + else + { + simpleParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - simpleParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + simpleParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); } return simpleParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index 44eb3d022..d3cf8a6e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,191 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + simpleQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - simpleQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + simpleQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - simpleQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - simpleQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index 35413600a..2e4812866 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index c6dea9921..68d422c8b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,155 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataAnnotationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataAnnotationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataAnnotation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataAnnotation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataAnnotation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataAnnotation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataAnnotation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataAnnotation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - siteDirectoryDataAnnotation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale primaryAnnotatedThing property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataAnnotation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataAnnotation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 03794401c..459029ada 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - siteDirectoryDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + siteDirectoryDataDiscussionItem.ReplyTo = null; + } + else + { + siteDirectoryDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index add3d1f0f..6c3350b55 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,239 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectory FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectory.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["annotation"].IsNullOrEmpty()) + var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("annotation"u8, out var annotationProperty) && annotationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Annotation.AddRange(jObject["annotation"].ToObject>()); + foreach(var element in annotationProperty.EnumerateArray()) + { + siteDirectory.Annotation.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectory.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["defaultParticipantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultParticipantRole"u8, out var defaultParticipantRoleProperty)) { - siteDirectory.DefaultParticipantRole = jObject["defaultParticipantRole"].ToObject(); + if(defaultParticipantRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultParticipantRole = null; + } + else + { + siteDirectory.DefaultParticipantRole = defaultParticipantRoleProperty.GetGuid(); + } } - if (!jObject["defaultPersonRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultPersonRole"u8, out var defaultPersonRoleProperty)) { - siteDirectory.DefaultPersonRole = jObject["defaultPersonRole"].ToObject(); + if(defaultPersonRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultPersonRole = null; + } + else + { + siteDirectory.DefaultPersonRole = defaultPersonRoleProperty.GetGuid(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + siteDirectory.Domain.Add(element.GetGuid()); + } } - if (!jObject["domainGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainGroup"u8, out var domainGroupProperty) && domainGroupProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.DomainGroup.AddRange(jObject["domainGroup"].ToObject>()); + foreach(var element in domainGroupProperty.EnumerateArray()) + { + siteDirectory.DomainGroup.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectory.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectory.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - siteDirectory.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale lastModifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + siteDirectory.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["model"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("model"u8, out var modelProperty) && modelProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Model.AddRange(jObject["model"].ToObject>()); + foreach(var element in modelProperty.EnumerateArray()) + { + siteDirectory.Model.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectory.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteDirectory.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.Name = nameProperty.GetString(); + } } - if (!jObject["naturalLanguage"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("naturalLanguage"u8, out var naturalLanguageProperty) && naturalLanguageProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.NaturalLanguage.AddRange(jObject["naturalLanguage"].ToObject>()); + foreach(var element in naturalLanguageProperty.EnumerateArray()) + { + siteDirectory.NaturalLanguage.Add(element.GetGuid()); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty) && organizationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Organization.AddRange(jObject["organization"].ToObject>()); + foreach(var element in organizationProperty.EnumerateArray()) + { + siteDirectory.Organization.Add(element.GetGuid()); + } } - if (!jObject["participantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantRole"u8, out var participantRoleProperty) && participantRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ParticipantRole.AddRange(jObject["participantRole"].ToObject>()); + foreach(var element in participantRoleProperty.EnumerateArray()) + { + siteDirectory.ParticipantRole.Add(element.GetGuid()); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty) && personProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Person.AddRange(jObject["person"].ToObject>()); + foreach(var element in personProperty.EnumerateArray()) + { + siteDirectory.Person.Add(element.GetGuid()); + } } - if (!jObject["personRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personRole"u8, out var personRoleProperty) && personRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.PersonRole.AddRange(jObject["personRole"].ToObject>()); + foreach(var element in personRoleProperty.EnumerateArray()) + { + siteDirectory.PersonRole.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteDirectory.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["siteReferenceDataLibrary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("siteReferenceDataLibrary"u8, out var siteReferenceDataLibraryProperty) && siteReferenceDataLibraryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.SiteReferenceDataLibrary.AddRange(jObject["siteReferenceDataLibrary"].ToObject>()); + foreach(var element in siteReferenceDataLibraryProperty.EnumerateArray()) + { + siteDirectory.SiteReferenceDataLibrary.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectory.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectory; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index 93f9951fd..11ccc900c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - siteDirectoryThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedRevisionNumber property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - siteDirectoryThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedThing property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index a812d610f..a3c5db285 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,171 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + siteLogEntry.Author = null; + } + else + { + siteLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + siteLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - siteLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale level property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + siteLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index a692f08e7..dd212ecb4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,151 +28,244 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - siteReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + siteReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + siteReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - siteReferenceDataLibrary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - siteReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + siteReferenceDataLibrary.RequiredRdl = null; + } + else + { + siteReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + siteReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return siteReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index 3c324f8a8..9d427ee8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SolutionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Solution FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var solution = new CDP4Common.DTO.Solution(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SolutionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - solution.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var solution = new CDP4Common.DTO.Solution(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - solution.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the solution {id} is null", solution.Iid); + } + else + { + solution.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - solution.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the solution {id} is null", solution.Iid); + } + else + { + solution.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - solution.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + solution.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + solution.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - solution.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the solution {id} is null", solution.Iid); + } + else + { + solution.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - solution.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - solution.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the solution {id} is null", solution.Iid); + } + else + { + solution.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - solution.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the solution {id} is null", solution.Iid); + } + else + { + solution.ThingPreference = thingPreferenceProperty.GetString(); + } } return solution; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index ba26de924..8c7076c26 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,203 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SpecializedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SpecializedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - specializedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + specializedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + specializedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - specializedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + specializedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["general"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("general"u8, out var generalProperty)) { - specializedQuantityKind.General = jObject["general"].ToObject(); + if(generalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale general property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.General = generalProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + specializedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - specializedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - specializedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - specializedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + specializedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - specializedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - specializedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - specializedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - specializedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return specializedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index 30eb2536f..5795d07a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,175 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeHolderValueMap.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeHolderValueMap.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeHolderValueMap.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + stakeHolderValueMap.Goal.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeHolderValueMap.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeHolderValueMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.Name = nameProperty.GetString(); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + stakeHolderValueMap.Requirement.Add(element.GetGuid()); + } } - if (!jObject["settings"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("settings"u8, out var settingsProperty) && settingsProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Settings.AddRange(jObject["settings"].ToObject>()); + foreach(var element in settingsProperty.EnumerateArray()) + { + stakeHolderValueMap.Settings.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeHolderValueMap.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeHolderValueMap.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + stakeHolderValueMap.ValueGroup.Add(element.GetGuid()); + } } return stakeHolderValueMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index 3df77b640..9863c5486 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,115 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapSettingsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapSettingsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMapSettings.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goalToValueGroupRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goalToValueGroupRelationship"u8, out var goalToValueGroupRelationshipProperty)) { - stakeHolderValueMapSettings.GoalToValueGroupRelationship = jObject["goalToValueGroupRelationship"].ToObject(); + if(goalToValueGroupRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = null; + } + else + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = goalToValueGroupRelationshipProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMapSettings.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["stakeholderValueToRequirementRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueToRequirementRelationship"u8, out var stakeholderValueToRequirementRelationshipProperty)) { - stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = jObject["stakeholderValueToRequirementRelationship"].ToObject(); + if(stakeholderValueToRequirementRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = null; + } + else + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = stakeholderValueToRequirementRelationshipProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMapSettings.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroupToStakeholderValueRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroupToStakeholderValueRelationship"u8, out var valueGroupToStakeholderValueRelationshipProperty)) { - stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = jObject["valueGroupToStakeholderValueRelationship"].ToObject(); + if(valueGroupToStakeholderValueRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = null; + } + else + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = valueGroupToStakeholderValueRelationshipProperty.GetGuid(); + } } return stakeHolderValueMapSettings; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index d7e472e93..2a4191a5a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,143 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Stakeholder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholder = new CDP4Common.DTO.Stakeholder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholder = new CDP4Common.DTO.Stakeholder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholder.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholder.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholder.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholder.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholder.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholder.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeholder.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeholder.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index 243b084ba..88d7c6a47 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeholderValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholderValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholderValue.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholderValue.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholderValue.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholderValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholderValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholderValue.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholderValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholderValue.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholderValue.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholderValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholderValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 814d54d53..95b744ffe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,99 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TelephoneNumberResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TelephoneNumberResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - telephoneNumber.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + telephoneNumber.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + telephoneNumber.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - telephoneNumber.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - telephoneNumber.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - telephoneNumber.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty) && vcardTypeProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.VcardType.AddRange(jObject["vcardType"].ToObject>()); + foreach(var element in vcardTypeProperty.EnumerateArray()) + { + telephoneNumber.VcardType.Add(VcardTelephoneNumberKindDeserializer.Deserialize(element)); + } } return telephoneNumber; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index 529bbcb2a..ed17540c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,139 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TermResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Term FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var term = new CDP4Common.DTO.Term(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TermResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - term.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var term = new CDP4Common.DTO.Term(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - term.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + term.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - term.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + term.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + term.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + term.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - term.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + term.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - term.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the term {id} is null", term.Iid); + } + else + { + term.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - term.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the term {id} is null", term.Iid); + } + else + { + term.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - term.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the term {id} is null", term.Iid); + } + else + { + term.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - term.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the term {id} is null", term.Iid); + } + else + { + term.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - term.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the term {id} is null", term.Iid); + } + else + { + term.ThingPreference = thingPreferenceProperty.GetString(); + } } return term; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index d81e72ab5..ae9fbb9d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textParameterType = new CDP4Common.DTO.TextParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var textParameterType = new CDP4Common.DTO.TextParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + textParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + textParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - textParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + textParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - textParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - textParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return textParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index 9680281f8..14391575e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextualNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextualNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textualNote = new CDP4Common.DTO.TextualNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextualNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textualNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var textualNote = new CDP4Common.DTO.TextualNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textualNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textualNote.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - textualNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - textualNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textualNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textualNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - textualNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textualNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textualNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - textualNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textualNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textualNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return textualNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index a9d1a9464..1cea57539 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,159 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TimeOfDayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TimeOfDayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - timeOfDayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + timeOfDayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + timeOfDayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + timeOfDayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + timeOfDayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - timeOfDayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - timeOfDayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - timeOfDayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - timeOfDayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - timeOfDayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - timeOfDayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return timeOfDayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index 2b9b8af79..217ebd135 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitFactor = new CDP4Common.DTO.UnitFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var unitFactor = new CDP4Common.DTO.UnitFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - unitFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - unitFactor.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Unit = unitProperty.GetGuid(); + } } return unitFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index 149a3f653..7871cf4e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,151 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitPrefixResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitPrefix FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitPrefixResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitPrefix.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + unitPrefix.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - unitPrefix.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale conversionFactor property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + unitPrefix.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitPrefix.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitPrefix.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + unitPrefix.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - unitPrefix.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitPrefix.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - unitPrefix.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - unitPrefix.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitPrefix.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ThingPreference = thingPreferenceProperty.GetString(); + } } return unitPrefix; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index 04e26203e..20bea1856 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,103 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserPreferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserPreference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userPreference = new CDP4Common.DTO.UserPreference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UserPreferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userPreference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var userPreference = new CDP4Common.DTO.UserPreference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userPreference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userPreference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userPreference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - userPreference.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userPreference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - userPreference.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.Value = valueProperty.GetString(); + } } return userPreference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index b7f77c8b2..d5edbfa43 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,127 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - userRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the UserRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - userRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + userRuleVerification.ExecutedOn = null; + } + else + { + userRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - userRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userRuleVerification.Rule = jObject["rule"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty)) { - userRuleVerification.Status = jObject["status"].ToObject(); + if(ruleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale rule property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Rule = ruleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - userRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return userRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index d979b91e6..b7cb379dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,135 @@ namespace CDP4JsonSerializer { - using System; - using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; - - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ValueGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ValueGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var valueGroup = new CDP4Common.DTO.ValueGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ValueGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - valueGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var valueGroup = new CDP4Common.DTO.ValueGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + valueGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + valueGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + valueGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + valueGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + valueGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - valueGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + valueGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - valueGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - valueGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - valueGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - valueGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return valueGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index b47d536d7..1084b3f83 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActionItem = CDP4Common.DTO.ActionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,104 +51,950 @@ namespace CDP4JsonSerializer public class ActionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actionee", actionee => new JValue(actionee) }, - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "closeOutDate", closeOutDate => new JValue(closeOutDate != null ? ((DateTime)closeOutDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "closeOutStatement", closeOutStatement => new JValue(closeOutStatement) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "dueDate", dueDate => new JValue(((DateTime)dueDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not ActionItem actionItem) + { + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActionItem actionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("actionee", this.PropertySerializerMap["actionee"](actionItem.Actionee)); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](actionItem.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](actionItem.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](actionItem.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), actionItem.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actionItem.ClassKind))); - jsonObject.Add("closeOutDate", this.PropertySerializerMap["closeOutDate"](actionItem.CloseOutDate)); - jsonObject.Add("closeOutStatement", this.PropertySerializerMap["closeOutStatement"](actionItem.CloseOutStatement)); - jsonObject.Add("content", this.PropertySerializerMap["content"](actionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](actionItem.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](actionItem.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dueDate", this.PropertySerializerMap["dueDate"](actionItem.DueDate)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](actionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actionItem.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actionItem.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](actionItem.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](actionItem.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actionItem.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](actionItem.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](actionItem.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), actionItem.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actionItem.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](actionItem.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.1.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.2.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.3.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WritePropertyName("actor"u8); + + if(actionItem.Actor.HasValue) + { + writer.WriteStringValue(actionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if(actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var actionItem = thing as ActionItem; - if (actionItem == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActionItem."); - } + case "actionee": + if(!AllowedVersionsPerProperty["actionee"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actionee"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutdate": + if(!AllowedVersionsPerProperty["closeOutDate"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("closeOutDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutstatement": + if(!AllowedVersionsPerProperty["closeOutStatement"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("closeOutStatement"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "duedate": + if(!AllowedVersionsPerProperty["dueDate"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("dueDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(actionItem); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actionee", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutStatement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "dueDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index 6df1d9164..b111405a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteStateList = CDP4Common.DTO.ActualFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,517 @@ namespace CDP4JsonSerializer public class ActualFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JArray(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(((IEnumerable)possibleFiniteStateList).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ActualFiniteStateList actualFiniteStateList) + { + throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteStateList actualFiniteStateList) - { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](actualFiniteStateList.ActualState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteStateList.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteStateList.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actualFiniteStateList.Owner)); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteStateList.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteStateList.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(actualFiniteStateList.Actor.HasValue) + { + writer.WriteStringValue(actualFiniteStateList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var actualFiniteStateList = thing as ActualFiniteStateList; - if (actualFiniteStateList == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActualFiniteStateList."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("actualState"u8); + + if(value is IEnumerable objectListActualState) + { + foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(actualFiniteStateList); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeoption": + if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludeOption"u8); + + if(value is IEnumerable objectListExcludeOption) + { + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblefinitestatelist": + if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteStateList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 40f2f6eed..f5addebc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,407 @@ namespace CDP4JsonSerializer public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "possibleState", possibleState => new JArray(possibleState) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteState actualFiniteState) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteState.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteState.Iid)); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ActualFiniteStateKind), actualFiniteState.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteState.ModifiedOn)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](actualFiniteState.PossibleState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteState.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteState.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(actualFiniteState.Actor.HasValue) + { + writer.WriteStringValue(actualFiniteState.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var actualFiniteState = thing as ActualFiniteState; - if (actualFiniteState == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActualFiniteState."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(actualFiniteState); + break; + case "kind": + if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((ActualFiniteStateKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleState"u8); + + if(value is IEnumerable objectListPossibleState) + { + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteState"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 15f35aa61..f9f993a00 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Alias = CDP4Common.DTO.Alias; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class AliasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isSynonym", isSynonym => new JValue(isSynonym) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Alias alias) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), alias.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](alias.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](alias.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](alias.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](alias.Iid)); - jsonObject.Add("isSynonym", this.PropertySerializerMap["isSynonym"](alias.IsSynonym)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](alias.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](alias.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](alias.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](alias.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(alias.Actor.HasValue) + { + writer.WriteStringValue(alias.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var alias = thing as Alias; - if (alias == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Alias."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "issynonym": + if(!AllowedVersionsPerProperty["isSynonym"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(alias); + writer.WritePropertyName("isSynonym"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Alias"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isSynonym", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 01328a0cb..cba482db8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using AndExpression = CDP4Common.DTO.AndExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +51,380 @@ namespace CDP4JsonSerializer public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(AndExpression andExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), andExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](andExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](andExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](andExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](andExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](andExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](andExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](andExpression.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(andExpression.Actor.HasValue) + { + writer.WriteStringValue(andExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var andExpression = thing as AndExpression; - if (andExpression == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a AndExpression."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(andExpression); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the AndExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 6b46febad..c05f4dd9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Approval = CDP4Common.DTO.Approval; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,466 @@ namespace CDP4JsonSerializer public class ApprovalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Approval approval) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](approval.Author)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationApprovalKind), approval.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), approval.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](approval.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](approval.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](approval.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](approval.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](approval.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](approval.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](approval.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](approval.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](approval.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](approval.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(approval.Actor.HasValue) + { + writer.WriteStringValue(approval.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var approval = thing as Approval; - if (approval == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Approval."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(approval); + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationApprovalKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Approval"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 0826099da..99a8b199c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ArrayParameterType = CDP4Common.DTO.ArrayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +51,817 @@ namespace CDP4JsonSerializer public class ArrayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "dimension", dimension => new JArray(((IEnumerable)dimension).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "isTensor", isTensor => new JValue(isTensor) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ArrayParameterType arrayParameterType) + { + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ArrayParameterType arrayParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](arrayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](arrayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), arrayParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](arrayParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](arrayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dimension", this.PropertySerializerMap["dimension"](arrayParameterType.Dimension.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](arrayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](arrayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](arrayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](arrayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](arrayParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](arrayParameterType.IsFinalized)); - jsonObject.Add("isTensor", this.PropertySerializerMap["isTensor"](arrayParameterType.IsTensor)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](arrayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](arrayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](arrayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](arrayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](arrayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](arrayParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(arrayParameterType.Actor.HasValue) + { + writer.WriteStringValue(arrayParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var arrayParameterType = thing as ArrayParameterType; - if (arrayParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ArrayParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("component"u8); + + if(value is IEnumerable objectListComponent) + { + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "dimension": + if(!AllowedVersionsPerProperty["dimension"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("dimension"u8); + + if(value is IEnumerable objectListDimension) + { + foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(arrayParameterType); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "istensor": + if(!AllowedVersionsPerProperty["isTensor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isTensor"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ArrayParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dimension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isTensor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 2f44fc8f9..4547107d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryNote = CDP4Common.DTO.BinaryNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,512 @@ namespace CDP4JsonSerializer public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "caption", caption => new JValue(caption) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JValue(fileType) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not BinaryNote binaryNote) + { + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryNote binaryNote) - { - var jsonObject = new JObject(); - jsonObject.Add("caption", this.PropertySerializerMap["caption"](binaryNote.Caption)); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryNote.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](binaryNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](binaryNote.FileType)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryNote.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryNote.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.1.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.2.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryNote.Actor.HasValue) + { + writer.WriteStringValue(binaryNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var binaryNote = thing as BinaryNote; - if (binaryNote == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryNote."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "caption": + if(!AllowedVersionsPerProperty["caption"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("caption"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fileType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(binaryNote); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "caption", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index c86f94811..79fbf3310 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationshipRule = CDP4Common.DTO.BinaryRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,706 @@ namespace CDP4JsonSerializer public class BinaryRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "forwardRelationshipName", forwardRelationshipName => new JValue(forwardRelationshipName) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "inverseRelationshipName", inverseRelationshipName => new JValue(inverseRelationshipName) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceCategory", sourceCategory => new JValue(sourceCategory) }, - { "targetCategory", targetCategory => new JValue(targetCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not BinaryRelationshipRule binaryRelationshipRule) + { + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationshipRule binaryRelationshipRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](binaryRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](binaryRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("forwardRelationshipName", this.PropertySerializerMap["forwardRelationshipName"](binaryRelationshipRule.ForwardRelationshipName)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](binaryRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationshipRule.Iid)); - jsonObject.Add("inverseRelationshipName", this.PropertySerializerMap["inverseRelationshipName"](binaryRelationshipRule.InverseRelationshipName)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](binaryRelationshipRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationshipRule.Name)); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](binaryRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryRelationshipRule.ShortName)); - jsonObject.Add("sourceCategory", this.PropertySerializerMap["sourceCategory"](binaryRelationshipRule.SourceCategory)); - jsonObject.Add("targetCategory", this.PropertySerializerMap["targetCategory"](binaryRelationshipRule.TargetCategory)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationshipRule.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationshipRule.Actor.HasValue) + { + writer.WriteStringValue(binaryRelationshipRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var binaryRelationshipRule = thing as BinaryRelationshipRule; - if (binaryRelationshipRule == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryRelationshipRule."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "forwardrelationshipname": + if(!AllowedVersionsPerProperty["forwardRelationshipName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("forwardRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "inverserelationshipname": + if(!AllowedVersionsPerProperty["inverseRelationshipName"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(binaryRelationshipRule); + writer.WritePropertyName("inverseRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationshipcategory": + if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourcecategory": + if(!AllowedVersionsPerProperty["sourceCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "targetcategory": + if(!AllowedVersionsPerProperty["targetCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("targetCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationshipRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "forwardRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "inverseRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "targetCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index a2de5d468..a719d0883 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationship = CDP4Common.DTO.BinaryRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,530 @@ namespace CDP4JsonSerializer public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not BinaryRelationship binaryRelationship) + { + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationship binaryRelationship) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](binaryRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationship.RevisionNumber)); - jsonObject.Add("source", this.PropertySerializerMap["source"](binaryRelationship.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](binaryRelationship.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationship.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(binaryRelationship.Actor.HasValue) + { + writer.WriteStringValue(binaryRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var binaryRelationship = thing as BinaryRelationship; - if (binaryRelationship == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryRelationship."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(binaryRelationship); + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationship"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index f8fa879fb..abc6c6d35 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Book = CDP4Common.DTO.Book; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,508 @@ namespace CDP4JsonSerializer public class BookSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "section", section => new JArray(((IEnumerable)section).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Book book) + { + throw new ArgumentException("The thing shall be a Book", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Book book) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](book.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), book.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](book.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](book.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](book.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](book.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](book.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](book.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](book.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](book.RevisionNumber)); - jsonObject.Add("section", this.PropertySerializerMap["section"](book.Section.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](book.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](book.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(book.Actor.HasValue) + { + writer.WriteStringValue(book.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var book = thing as Book; - if (book == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Book."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(book); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "section": + if(!AllowedVersionsPerProperty["section"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("section"u8); + + if(value is IEnumerable objectListSection) + { + foreach(var sectionItem in objectListSection.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Book"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "section", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index 4deab3491..60566d570 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BooleanParameterType = CDP4Common.DTO.BooleanParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class BooleanParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not BooleanParameterType booleanParameterType) + { + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BooleanParameterType booleanParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](booleanParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](booleanParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), booleanParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](booleanParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](booleanParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](booleanParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](booleanParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](booleanParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](booleanParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](booleanParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](booleanParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](booleanParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](booleanParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](booleanParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](booleanParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(booleanParameterType.Actor.HasValue) + { + writer.WriteStringValue(booleanParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var booleanParameterType = thing as BooleanParameterType; - if (booleanParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BooleanParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(booleanParameterType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BooleanParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index cdf0514ef..a20241ef0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Bounds = CDP4Common.DTO.Bounds; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,441 @@ namespace CDP4JsonSerializer public class BoundsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "height", height => new JValue(height) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "width", width => new JValue(width) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + if (thing is not Bounds bounds) + { + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Bounds bounds) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), bounds.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](bounds.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](bounds.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("height", this.PropertySerializerMap["height"](bounds.Height)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](bounds.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](bounds.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](bounds.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](bounds.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](bounds.ThingPreference)); - jsonObject.Add("width", this.PropertySerializerMap["width"](bounds.Width)); - jsonObject.Add("x", this.PropertySerializerMap["x"](bounds.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](bounds.Y)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(bounds.Actor.HasValue) + { + writer.WriteStringValue(bounds.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var bounds = thing as Bounds; - if (bounds == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Bounds."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "height": + if(!AllowedVersionsPerProperty["height"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("height"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(bounds); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "width": + if(!AllowedVersionsPerProperty["width"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("width"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Bounds"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "height", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "width", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 4901aa921..9ae30150d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BuiltInRuleVerification = CDP4Common.DTO.BuiltInRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -45,75 +51,524 @@ namespace CDP4JsonSerializer public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + if (thing is not BuiltInRuleVerification builtInRuleVerification) + { + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(BuiltInRuleVerification builtInRuleVerification) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), builtInRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](builtInRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](builtInRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](builtInRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](builtInRuleVerification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](builtInRuleVerification.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](builtInRuleVerification.RevisionNumber)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), builtInRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](builtInRuleVerification.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(builtInRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var builtInRuleVerification = thing as BuiltInRuleVerification; - if (builtInRuleVerification == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BuiltInRuleVerification."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "executedon": + if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(builtInRuleVerification); + break; + case "isactive": + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violation": + if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violation"u8); + + if(value is IEnumerable objectListViolation) + { + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BuiltInRuleVerification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index d96c7a383..92545d84e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Category = CDP4Common.DTO.Category; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,708 @@ namespace CDP4JsonSerializer public class CategorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isAbstract", isAbstract => new JValue(isAbstract) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "permissibleClass", permissibleClass => new JArray(permissibleClass) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "superCategory", superCategory => new JArray(superCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Category category) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](category.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), category.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](category.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](category.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](category.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](category.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](category.Iid)); - jsonObject.Add("isAbstract", this.PropertySerializerMap["isAbstract"](category.IsAbstract)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](category.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](category.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](category.Name)); - jsonObject.Add("permissibleClass", this.PropertySerializerMap["permissibleClass"](category.PermissibleClass.Select(e => Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), e)))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](category.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](category.ShortName)); - jsonObject.Add("superCategory", this.PropertySerializerMap["superCategory"](category.SuperCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](category.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(category.Actor.HasValue) + { + writer.WriteStringValue(category.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var category = thing as Category; - if (category == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Category."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(category); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isabstract": + if(!AllowedVersionsPerProperty["isAbstract"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isAbstract"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "permissibleclass": + if(!AllowedVersionsPerProperty["permissibleClass"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("permissibleClass"u8); + + if(value is IEnumerable objectListPermissibleClass) + { + foreach(var permissibleClassItem in objectListPermissibleClass) + { + writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "supercategory": + if(!AllowedVersionsPerProperty["superCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("superCategory"u8); + + if(value is IEnumerable objectListSuperCategory) + { + foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Category"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAbstract", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "permissibleClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "superCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index d0b700b5f..f51c63661 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeProposal = CDP4Common.DTO.ChangeProposal; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +51,848 @@ namespace CDP4JsonSerializer public class ChangeProposalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeRequest", changeRequest => new JValue(changeRequest) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not ChangeProposal changeProposal) + { + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ChangeProposal changeProposal) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeProposal.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeProposal.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeProposal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeRequest", this.PropertySerializerMap["changeRequest"](changeProposal.ChangeRequest)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeProposal.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeProposal.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeProposal.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeProposal.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeProposal.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeProposal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeProposal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeProposal.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeProposal.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeProposal.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeProposal.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeProposal.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeProposal.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeProposal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeProposal.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeProposal.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeProposal.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeProposal.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeProposal.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeProposal.Actor.HasValue) + { + writer.WriteStringValue(changeProposal.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var changeProposal = thing as ChangeProposal; - if (changeProposal == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ChangeProposal."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "changerequest": + if(!AllowedVersionsPerProperty["changeRequest"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeRequest"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(changeProposal); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeProposal"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeRequest", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index e5ac3ab78..a7b2b58e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeRequest = CDP4Common.DTO.ChangeRequest; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +51,823 @@ namespace CDP4JsonSerializer public class ChangeRequestSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ChangeRequest changeRequest) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeRequest.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeRequest.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeRequest.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeRequest.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeRequest.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeRequest.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeRequest.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeRequest.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeRequest.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeRequest.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeRequest.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeRequest.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeRequest.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeRequest.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeRequest.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeRequest.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeRequest.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeRequest.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeRequest.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeRequest.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeRequest.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeRequest.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(changeRequest.Actor.HasValue) + { + writer.WriteStringValue(changeRequest.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var changeRequest = thing as ChangeRequest; - if (changeRequest == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ChangeRequest."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(changeRequest); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeRequest"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index e1d25a099..423ff51c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Citation = CDP4Common.DTO.Citation; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,460 @@ namespace CDP4JsonSerializer public class CitationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isAdaptation", isAdaptation => new JValue(isAdaptation) }, - { "location", location => new JValue(location) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "remark", remark => new JValue(remark) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "source", source => new JValue(source) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Citation citation) + { + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Citation citation) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), citation.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](citation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](citation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](citation.Iid)); - jsonObject.Add("isAdaptation", this.PropertySerializerMap["isAdaptation"](citation.IsAdaptation)); - jsonObject.Add("location", this.PropertySerializerMap["location"](citation.Location)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](citation.ModifiedOn)); - jsonObject.Add("remark", this.PropertySerializerMap["remark"](citation.Remark)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](citation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](citation.ShortName)); - jsonObject.Add("source", this.PropertySerializerMap["source"](citation.Source)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](citation.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(citation.Actor.HasValue) + { + writer.WriteStringValue(citation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var citation = thing as Citation; - if (citation == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Citation."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isadaptation": + if(!AllowedVersionsPerProperty["isAdaptation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isAdaptation"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "location": + if(!AllowedVersionsPerProperty["location"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("location"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(citation); + break; + case "remark": + if(!AllowedVersionsPerProperty["remark"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("remark"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Citation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAdaptation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "location", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "remark", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 2db0a4d15..24f898ef3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Color = CDP4Common.DTO.Color; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,433 @@ namespace CDP4JsonSerializer public class ColorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "blue", blue => new JValue(blue) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "green", green => new JValue(green) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "red", red => new JValue(red) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Color color) + { + throw new ArgumentException("The thing shall be a Color", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Color color) - { - var jsonObject = new JObject(); - jsonObject.Add("blue", this.PropertySerializerMap["blue"](color.Blue)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), color.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](color.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](color.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("green", this.PropertySerializerMap["green"](color.Green)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](color.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](color.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](color.Name)); - jsonObject.Add("red", this.PropertySerializerMap["red"](color.Red)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](color.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](color.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.0.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.1.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.2.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(color.Actor.HasValue) + { + writer.WriteStringValue(color.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var color = thing as Color; - if (color == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Color."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "blue": + if(!AllowedVersionsPerProperty["blue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("blue"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "green": + if(!AllowedVersionsPerProperty["green"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("green"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(color); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "red": + if(!AllowedVersionsPerProperty["red"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("red"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Color"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "blue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "green", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "red", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 4b381bcb0..f246db2b5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CommonFileStore = CDP4Common.DTO.CommonFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,516 @@ namespace CDP4JsonSerializer public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not CommonFileStore commonFileStore) + { + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CommonFileStore commonFileStore) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), commonFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](commonFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](commonFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](commonFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](commonFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](commonFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](commonFileStore.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](commonFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](commonFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](commonFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](commonFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](commonFileStore.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(commonFileStore.Actor.HasValue) + { + writer.WriteStringValue(commonFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var commonFileStore = thing as CommonFileStore; - if (commonFileStore == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CommonFileStore."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "file": + if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("file"u8); - return this.Serialize(commonFileStore); + if(value is IEnumerable objectListFile) + { + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + } + + writer.WriteEndArray(); + break; + case "folder": + if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("folder"u8); + + if(value is IEnumerable objectListFolder) + { + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CommonFileStore"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index d34112269..09cc7998b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CompoundParameterType = CDP4Common.DTO.CompoundParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,735 @@ namespace CDP4JsonSerializer public class CompoundParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CompoundParameterType compoundParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](compoundParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](compoundParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), compoundParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](compoundParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](compoundParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](compoundParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](compoundParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](compoundParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](compoundParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](compoundParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](compoundParameterType.IsFinalized)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](compoundParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](compoundParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](compoundParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](compoundParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](compoundParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](compoundParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(compoundParameterType.Actor.HasValue) + { + writer.WriteStringValue(compoundParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var compoundParameterType = thing as CompoundParameterType; - if (compoundParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CompoundParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("component"u8); + + if(value is IEnumerable objectListComponent) + { + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(compoundParameterType); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CompoundParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index 63f11b496..412e656be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Constant = CDP4Common.DTO.Constant; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,729 @@ namespace CDP4JsonSerializer public class ConstantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + if (thing is not Constant constant) + { + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Constant constant) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](constant.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](constant.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), constant.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](constant.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](constant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](constant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](constant.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](constant.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](constant.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](constant.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](constant.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](constant.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](constant.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](constant.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](constant.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](constant.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](constant.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(constant.Actor.HasValue) + { + writer.WriteStringValue(constant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var constant = thing as Constant; - if (constant == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Constant."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(constant); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Constant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 9fad3d594..8d6aaf3db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ContractChangeNotice = CDP4Common.DTO.ContractChangeNotice; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +51,848 @@ namespace CDP4JsonSerializer public class ContractChangeNoticeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeProposal", changeProposal => new JValue(changeProposal) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not ContractChangeNotice contractChangeNotice) + { + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ContractChangeNotice contractChangeNotice) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](contractChangeNotice.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](contractChangeNotice.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](contractChangeNotice.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeProposal", this.PropertySerializerMap["changeProposal"](contractChangeNotice.ChangeProposal)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), contractChangeNotice.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), contractChangeNotice.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](contractChangeNotice.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](contractChangeNotice.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](contractChangeNotice.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](contractChangeNotice.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](contractChangeNotice.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](contractChangeNotice.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](contractChangeNotice.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](contractChangeNotice.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](contractChangeNotice.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](contractChangeNotice.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](contractChangeNotice.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), contractChangeNotice.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](contractChangeNotice.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](contractChangeNotice.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(contractChangeNotice.Actor.HasValue) + { + writer.WriteStringValue(contractChangeNotice.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var contractChangeNotice = thing as ContractChangeNotice; - if (contractChangeNotice == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ContractChangeNotice."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "changeproposal": + if(!AllowedVersionsPerProperty["changeProposal"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeProposal"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(contractChangeNotice); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ContractChangeNotice"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeProposal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index d84dd99e9..e8a0f05f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CyclicRatioScale = CDP4Common.DTO.CyclicRatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +51,924 @@ namespace CDP4JsonSerializer public class CyclicRatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "modulus", modulus => new JValue(modulus) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + if (thing is not CyclicRatioScale cyclicRatioScale) + { + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(CyclicRatioScale cyclicRatioScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](cyclicRatioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), cyclicRatioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](cyclicRatioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](cyclicRatioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](cyclicRatioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](cyclicRatioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](cyclicRatioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](cyclicRatioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](cyclicRatioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](cyclicRatioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](cyclicRatioScale.ModifiedOn)); - jsonObject.Add("modulus", this.PropertySerializerMap["modulus"](cyclicRatioScale.Modulus)); - jsonObject.Add("name", this.PropertySerializerMap["name"](cyclicRatioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](cyclicRatioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), cyclicRatioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](cyclicRatioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](cyclicRatioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](cyclicRatioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](cyclicRatioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](cyclicRatioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(cyclicRatioScale.Actor.HasValue) + { + writer.WriteStringValue(cyclicRatioScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var cyclicRatioScale = thing as CyclicRatioScale; - if (cyclicRatioScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CyclicRatioScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); - return this.Serialize(cyclicRatioScale); + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modulus": + if(!AllowedVersionsPerProperty["modulus"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modulus"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CyclicRatioScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modulus", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 3d0909bda..9e479ed0c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateParameterType = CDP4Common.DTO.DateParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class DateParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DateParameterType dateParameterType) + { + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DateParameterType dateParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dateParameterType.Actor.HasValue) + { + writer.WriteStringValue(dateParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var dateParameterType = thing as DateParameterType; - if (dateParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DateParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(dateParameterType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index c2d3264cf..c75c8db26 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateTimeParameterType = CDP4Common.DTO.DateTimeParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class DateTimeParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DateTimeParameterType dateTimeParameterType) + { + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DateTimeParameterType dateTimeParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateTimeParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateTimeParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateTimeParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateTimeParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateTimeParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateTimeParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateTimeParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateTimeParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateTimeParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateTimeParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateTimeParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateTimeParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateTimeParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dateTimeParameterType.Actor.HasValue) + { + writer.WriteStringValue(dateTimeParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var dateTimeParameterType = thing as DateTimeParameterType; - if (dateTimeParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DateTimeParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(dateTimeParameterType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateTimeParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index d0bf402ec..1bcb6fc13 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DecompositionRule = CDP4Common.DTO.DecompositionRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,743 @@ namespace CDP4JsonSerializer public class DecompositionRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedCategory", containedCategory => new JArray(containedCategory) }, - { "containingCategory", containingCategory => new JValue(containingCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxContained", maxContained => new JValue(maxContained) }, - { "minContained", minContained => new JValue(minContained) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DecompositionRule decompositionRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](decompositionRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), decompositionRule.ClassKind))); - jsonObject.Add("containedCategory", this.PropertySerializerMap["containedCategory"](decompositionRule.ContainedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("containingCategory", this.PropertySerializerMap["containingCategory"](decompositionRule.ContainingCategory)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](decompositionRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](decompositionRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](decompositionRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](decompositionRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](decompositionRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](decompositionRule.IsDeprecated)); - jsonObject.Add("maxContained", this.PropertySerializerMap["maxContained"](decompositionRule.MaxContained)); - jsonObject.Add("minContained", this.PropertySerializerMap["minContained"](decompositionRule.MinContained)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](decompositionRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](decompositionRule.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](decompositionRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](decompositionRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](decompositionRule.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(decompositionRule.Actor.HasValue) + { + writer.WriteStringValue(decompositionRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if(decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var decompositionRule = thing as DecompositionRule; - if (decompositionRule == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DecompositionRule."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedcategory": + if(!AllowedVersionsPerProperty["containedCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("containedCategory"u8); + + if(value is IEnumerable objectListContainedCategory) + { + foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "containingcategory": + if(!AllowedVersionsPerProperty["containingCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(decompositionRule); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxcontained": + if(!AllowedVersionsPerProperty["maxContained"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mincontained": + if(!AllowedVersionsPerProperty["minContained"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DecompositionRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 85bb31058..8554d8d6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Definition = CDP4Common.DTO.Definition; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,544 @@ namespace CDP4JsonSerializer public class DefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "citation", citation => new JArray(citation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "example", example => new JArray(((IEnumerable)example).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Definition definition) + { + throw new ArgumentException("The thing shall be a Definition", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Definition definition) - { - var jsonObject = new JObject(); - jsonObject.Add("citation", this.PropertySerializerMap["citation"](definition.Citation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), definition.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](definition.Content)); - jsonObject.Add("example", this.PropertySerializerMap["example"](definition.Example.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](definition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](definition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](definition.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](definition.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](definition.ModifiedOn)); - jsonObject.Add("note", this.PropertySerializerMap["note"](definition.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](definition.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](definition.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(definition.Actor.HasValue) + { + writer.WriteStringValue(definition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var definition = thing as Definition; - if (definition == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Definition."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "citation": + if(!AllowedVersionsPerProperty["citation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("citation"u8); + + if(value is IEnumerable objectListCitation) + { + foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "example": + if(!AllowedVersionsPerProperty["example"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("example"u8); - return this.Serialize(definition); + if(value is IEnumerable objectListExample) + { + foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("note"u8); + + if(value is IEnumerable objectListNote) + { + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Definition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "citation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "example", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 62f0f45ec..9242d2ad8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DependentParameterTypeAssignment = CDP4Common.DTO.DependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,351 @@ namespace CDP4JsonSerializer public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DependentParameterTypeAssignment dependentParameterTypeAssignment) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dependentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dependentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](dependentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dependentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](dependentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dependentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dependentParameterTypeAssignment.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(dependentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var dependentParameterTypeAssignment = thing as DependentParameterTypeAssignment; - if (dependentParameterTypeAssignment == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DependentParameterTypeAssignment."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(dependentParameterTypeAssignment); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DependentParameterTypeAssignment"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index 2c7858062..f44c6f3fe 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedQuantityKind = CDP4Common.DTO.DerivedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +51,817 @@ namespace CDP4JsonSerializer public class DerivedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "quantityKindFactor", quantityKindFactor => new JArray(((IEnumerable)quantityKindFactor).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DerivedQuantityKind derivedQuantityKind) + { + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DerivedQuantityKind derivedQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](derivedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](derivedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](derivedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](derivedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("quantityKindFactor", this.PropertySerializerMap["quantityKindFactor"](derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](derivedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedQuantityKind.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(derivedQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var derivedQuantityKind = thing as DerivedQuantityKind; - if (derivedQuantityKind == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DerivedQuantityKind."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(derivedQuantityKind); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykindfactor": + if(!AllowedVersionsPerProperty["quantityKindFactor"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("quantityKindFactor"u8); + + if(value is IEnumerable objectListQuantityKindFactor) + { + foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKindFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index d9aee87fa..100c65783 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedUnit = CDP4Common.DTO.DerivedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class DerivedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unitFactor", unitFactor => new JArray(((IEnumerable)unitFactor).Cast().Select(x => x.ToJsonObject())) }, - }; + if (thing is not DerivedUnit derivedUnit) + { + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DerivedUnit derivedUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedUnit.ThingPreference)); - jsonObject.Add("unitFactor", this.PropertySerializerMap["unitFactor"](derivedUnit.UnitFactor.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(derivedUnit.Actor.HasValue) + { + writer.WriteStringValue(derivedUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var derivedUnit = thing as DerivedUnit; - if (derivedUnit == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DerivedUnit."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(derivedUnit); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unitfactor": + if(!AllowedVersionsPerProperty["unitFactor"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitFactor"u8); + + if(value is IEnumerable objectListUnitFactor) + { + foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unitFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index 773c02c82..f63fa3c49 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramCanvas = CDP4Common.DTO.DiagramCanvas; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,458 @@ namespace CDP4JsonSerializer public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DiagramCanvas diagramCanvas) + { + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramCanvas diagramCanvas) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramCanvas.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramCanvas.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](diagramCanvas.CreatedOn)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramCanvas.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramCanvas.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramCanvas.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramCanvas.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramCanvas.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramCanvas.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramCanvas.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramCanvas.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramCanvas.Actor.HasValue) + { + writer.WriteStringValue(diagramCanvas.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var diagramCanvas = thing as DiagramCanvas; - if (diagramCanvas == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramCanvas."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(diagramCanvas); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramCanvas"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 9c1806bf5..bd83b5099 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramEdge = CDP4Common.DTO.DiagramEdge; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,679 @@ namespace CDP4JsonSerializer public class DiagramEdgeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "point", point => new JArray(((IEnumerable)point).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramEdge diagramEdge) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramEdge.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramEdge.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramEdge.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramEdge.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramEdge.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramEdge.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramEdge.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramEdge.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramEdge.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramEdge.Name)); - jsonObject.Add("point", this.PropertySerializerMap["point"](diagramEdge.Point.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramEdge.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramEdge.SharedStyle)); - jsonObject.Add("source", this.PropertySerializerMap["source"](diagramEdge.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](diagramEdge.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramEdge.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramEdge.Actor.HasValue) + { + writer.WriteStringValue(diagramEdge.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var diagramEdge = thing as DiagramEdge; - if (diagramEdge == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramEdge."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(diagramEdge); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "localstyle": + if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("localStyle"u8); + + if(value is IEnumerable objectListLocalStyle) + { + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "point": + if(!AllowedVersionsPerProperty["point"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("point"u8); + + if(value is IEnumerable objectListPoint) + { + foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramEdge"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "point", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 80b020c56..8c6f2971d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramObject = CDP4Common.DTO.DiagramObject; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,633 @@ namespace CDP4JsonSerializer public class DiagramObjectSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "documentation", documentation => new JValue(documentation) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "resolution", resolution => new JValue(resolution) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DiagramObject diagramObject) + { + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DiagramObject diagramObject) - { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramObject.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramObject.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramObject.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramObject.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("documentation", this.PropertySerializerMap["documentation"](diagramObject.Documentation)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramObject.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramObject.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramObject.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramObject.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramObject.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramObject.Name)); - jsonObject.Add("resolution", this.PropertySerializerMap["resolution"](diagramObject.Resolution)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramObject.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramObject.SharedStyle)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramObject.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(diagramObject.Actor.HasValue) + { + writer.WriteStringValue(diagramObject.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if(diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if(diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var diagramObject = thing as DiagramObject; - if (diagramObject == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramObject."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "bounds": + if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("bounds"u8); + + if(value is IEnumerable objectListBounds) + { + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramElement"u8); + + if(value is IEnumerable objectListDiagramElement) + { + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + } + + writer.WriteEndArray(); + break; + case "documentation": + if(!AllowedVersionsPerProperty["documentation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("documentation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(diagramObject); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "localstyle": + if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("localStyle"u8); + + if(value is IEnumerable objectListLocalStyle) + { + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "resolution": + if(!AllowedVersionsPerProperty["resolution"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("resolution"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramObject"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "documentation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "resolution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index b52b01732..487b8d342 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainFileStore = CDP4Common.DTO.DomainFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,543 @@ namespace CDP4JsonSerializer public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "isHidden", isHidden => new JValue(isHidden) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DomainFileStore domainFileStore) + { + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainFileStore domainFileStore) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](domainFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](domainFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](domainFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainFileStore.Iid)); - jsonObject.Add("isHidden", this.PropertySerializerMap["isHidden"](domainFileStore.IsHidden)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](domainFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainFileStore.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainFileStore.Actor.HasValue) + { + writer.WriteStringValue(domainFileStore.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var domainFileStore = thing as DomainFileStore; - if (domainFileStore == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainFileStore."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "file": + if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("file"u8); + + if(value is IEnumerable objectListFile) + { + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + } + + writer.WriteEndArray(); + break; + case "folder": + if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("folder"u8); - return this.Serialize(domainFileStore); + if(value is IEnumerable objectListFolder) + { + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ishidden": + if(!AllowedVersionsPerProperty["isHidden"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isHidden"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainFileStore"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isHidden", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index bce3425b1..0b6e75b6d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertiseGroup = CDP4Common.DTO.DomainOfExpertiseGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) + { + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertiseGroup domainOfExpertiseGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertiseGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertiseGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertiseGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](domainOfExpertiseGroup.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertiseGroup.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertiseGroup.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertiseGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertiseGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertiseGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertiseGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertiseGroup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainOfExpertiseGroup.Actor.HasValue) + { + writer.WriteStringValue(domainOfExpertiseGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var domainOfExpertiseGroup = thing as DomainOfExpertiseGroup; - if (domainOfExpertiseGroup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainOfExpertiseGroup."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(domainOfExpertiseGroup); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertiseGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index ad58a6e15..27e14bd41 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertise = CDP4Common.DTO.DomainOfExpertise; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not DomainOfExpertise domainOfExpertise) + { + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertise domainOfExpertise) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertise.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](domainOfExpertise.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertise.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertise.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertise.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertise.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertise.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertise.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertise.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertise.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertise.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertise.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(domainOfExpertise.Actor.HasValue) + { + writer.WriteStringValue(domainOfExpertise.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var domainOfExpertise = thing as DomainOfExpertise; - if (domainOfExpertise == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainOfExpertise."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(domainOfExpertise); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertise"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index 50e97bc99..dfb690303 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementDefinition = CDP4Common.DTO.ElementDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +51,883 @@ namespace CDP4JsonSerializer public class ElementDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedElement", containedElement => new JArray(containedElement) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JArray(parameter) }, - { "parameterGroup", parameterGroup => new JArray(parameterGroup) }, - { "referencedElement", referencedElement => new JArray(referencedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ElementDefinition elementDefinition) + { + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ElementDefinition elementDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementDefinition.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementDefinition.ClassKind))); - jsonObject.Add("containedElement", this.PropertySerializerMap["containedElement"](elementDefinition.ContainedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementDefinition.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementDefinition.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](elementDefinition.Parameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterGroup", this.PropertySerializerMap["parameterGroup"](elementDefinition.ParameterGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencedElement", this.PropertySerializerMap["referencedElement"](elementDefinition.ReferencedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementDefinition.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(elementDefinition.Actor.HasValue) + { + writer.WriteStringValue(elementDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var elementDefinition = thing as ElementDefinition; - if (elementDefinition == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ElementDefinition."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedelement": + if(!AllowedVersionsPerProperty["containedElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("containedElement"u8); - return this.Serialize(elementDefinition); + if(value is IEnumerable objectListContainedElement) + { + foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organizationalParticipant"u8); + + if(value is IEnumerable objectListOrganizationalParticipant) + { + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + } + + writer.WriteEndArray(); + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameter"u8); + + if(value is IEnumerable objectListParameter) + { + foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + } + + writer.WriteEndArray(); + break; + case "parametergroup": + if(!AllowedVersionsPerProperty["parameterGroup"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterGroup"u8); + + if(value is IEnumerable objectListParameterGroup) + { + foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + } + + writer.WriteEndArray(); + break; + case "referencedelement": + if(!AllowedVersionsPerProperty["referencedElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referencedElement"u8); + + if(value is IEnumerable objectListReferencedElement) + { + foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 37d4d6f01..b2751cf4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementUsage = CDP4Common.DTO.ElementUsage; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,790 @@ namespace CDP4JsonSerializer public class ElementUsageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "elementDefinition", elementDefinition => new JValue(elementDefinition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "interfaceEnd", interfaceEnd => new JValue(interfaceEnd.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterOverride", parameterOverride => new JArray(parameterOverride) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ElementUsage elementUsage) + { + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ElementUsage elementUsage) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementUsage.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementUsage.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementUsage.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementUsage.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("elementDefinition", this.PropertySerializerMap["elementDefinition"](elementUsage.ElementDefinition)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementUsage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementUsage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](elementUsage.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementUsage.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementUsage.Iid)); - jsonObject.Add("interfaceEnd", this.PropertySerializerMap["interfaceEnd"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.InterfaceEndKind), elementUsage.InterfaceEnd))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementUsage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementUsage.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementUsage.Owner)); - jsonObject.Add("parameterOverride", this.PropertySerializerMap["parameterOverride"](elementUsage.ParameterOverride.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementUsage.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementUsage.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementUsage.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(elementUsage.Actor.HasValue) + { + writer.WriteStringValue(elementUsage.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var elementUsage = thing as ElementUsage; - if (elementUsage == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ElementUsage."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "elementdefinition": + if(!AllowedVersionsPerProperty["elementDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("elementDefinition"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(elementUsage); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeoption": + if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludeOption"u8); + + if(value is IEnumerable objectListExcludeOption) + { + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "interfaceend": + if(!AllowedVersionsPerProperty["interfaceEnd"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("interfaceEnd"u8); + + if(value != null) + { + writer.WriteStringValue(((InterfaceEndKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameteroverride": + if(!AllowedVersionsPerProperty["parameterOverride"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterOverride"u8); + + if(value is IEnumerable objectListParameterOverride) + { + foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementUsage"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "interfaceEnd", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index b0f73d2e7..917f19f7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EmailAddress = CDP4Common.DTO.EmailAddress; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JValue(vcardType.ToString()) }, - }; + if (thing is not EmailAddress emailAddress) + { + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EmailAddress emailAddress) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), emailAddress.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](emailAddress.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](emailAddress.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](emailAddress.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](emailAddress.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](emailAddress.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](emailAddress.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](emailAddress.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardEmailAddressKind), emailAddress.VcardType))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(emailAddress.Actor.HasValue) + { + writer.WriteStringValue(emailAddress.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var emailAddress = thing as EmailAddress; - if (emailAddress == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EmailAddress."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(emailAddress); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("vcardType"u8); + + if(value != null) + { + writer.WriteStringValue(((VcardEmailAddressKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EmailAddress"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index d2b25d1cd..86eb793bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataDiscussionItem = CDP4Common.DTO.EngineeringModelDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,468 @@ namespace CDP4JsonSerializer public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](engineeringModelDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataDiscussionItem.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var engineeringModelDataDiscussionItem = thing as EngineeringModelDataDiscussionItem; - if (engineeringModelDataDiscussionItem == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataDiscussionItem."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(engineeringModelDataDiscussionItem); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataDiscussionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 229835157..fc7c747ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataNote = CDP4Common.DTO.EngineeringModelDataNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,560 @@ namespace CDP4JsonSerializer public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not EngineeringModelDataNote engineeringModelDataNote) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataNote engineeringModelDataNote) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataNote.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataNote.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](engineeringModelDataNote.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataNote.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](engineeringModelDataNote.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataNote.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataNote.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModelDataNote.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var engineeringModelDataNote = thing as EngineeringModelDataNote; - if (engineeringModelDataNote == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataNote."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(engineeringModelDataNote); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 37cf96788..307e41233 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModel = CDP4Common.DTO.EngineeringModel; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,682 @@ namespace CDP4JsonSerializer public class EngineeringModelSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "book", book => new JArray(((IEnumerable)book).Cast().Select(x => x.ToJsonObject())) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "commonFileStore", commonFileStore => new JArray(commonFileStore) }, - { "engineeringModelSetup", engineeringModelSetup => new JValue(engineeringModelSetup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "genericNote", genericNote => new JArray(genericNote) }, - { "iid", iid => new JValue(iid) }, - { "iteration", iteration => new JArray(iteration) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "modellingAnnotation", modellingAnnotation => new JArray(modellingAnnotation) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not EngineeringModel engineeringModel) + { + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModel engineeringModel) - { - var jsonObject = new JObject(); - jsonObject.Add("book", this.PropertySerializerMap["book"](engineeringModel.Book.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModel.ClassKind))); - jsonObject.Add("commonFileStore", this.PropertySerializerMap["commonFileStore"](engineeringModel.CommonFileStore)); - jsonObject.Add("engineeringModelSetup", this.PropertySerializerMap["engineeringModelSetup"](engineeringModel.EngineeringModelSetup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModel.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModel.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("genericNote", this.PropertySerializerMap["genericNote"](engineeringModel.GenericNote.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModel.Iid)); - jsonObject.Add("iteration", this.PropertySerializerMap["iteration"](engineeringModel.Iteration.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](engineeringModel.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](engineeringModel.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modellingAnnotation", this.PropertySerializerMap["modellingAnnotation"](engineeringModel.ModellingAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModel.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModel.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModel.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(engineeringModel.Actor.HasValue) + { + writer.WriteStringValue(engineeringModel.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var engineeringModel = thing as EngineeringModel; - if (engineeringModel == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModel."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "book": + if(!AllowedVersionsPerProperty["book"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("book"u8); + + if(value is IEnumerable objectListBook) + { + foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "commonfilestore": + if(!AllowedVersionsPerProperty["commonFileStore"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("commonFileStore"u8); + + if(value is IEnumerable objectListCommonFileStore) + { + foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + } + + writer.WriteEndArray(); + break; + case "engineeringmodelsetup": + if(!AllowedVersionsPerProperty["engineeringModelSetup"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("engineeringModelSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(engineeringModel); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "genericnote": + if(!AllowedVersionsPerProperty["genericNote"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("genericNote"u8); + + if(value is IEnumerable objectListGenericNote) + { + foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iteration": + if(!AllowedVersionsPerProperty["iteration"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("iteration"u8); + + if(value is IEnumerable objectListIteration) + { + foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + } + + writer.WriteEndArray(); + break; + case "lastmodifiedon": + if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntry"u8); + + if(value is IEnumerable objectListLogEntry) + { + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + } + + writer.WriteEndArray(); + break; + case "modellingannotation": + if(!AllowedVersionsPerProperty["modellingAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("modellingAnnotation"u8); + + if(value is IEnumerable objectListModellingAnnotation) + { + foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModel"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "book", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "commonFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "genericNote", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iteration", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modellingAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index b6c79aed6..7ee57ff94 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelSetup = CDP4Common.DTO.EngineeringModelSetup; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +51,986 @@ namespace CDP4JsonSerializer public class EngineeringModelSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "activeDomain", activeDomain => new JArray(activeDomain) }, - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOrganizationalParticipant", defaultOrganizationalParticipant => new JValue(defaultOrganizationalParticipant) }, - { "definition", definition => new JArray(definition) }, - { "engineeringModelIid", engineeringModelIid => new JValue(engineeringModelIid) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JArray(iterationSetup) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "participant", participant => new JArray(participant) }, - { "requiredRdl", requiredRdl => new JArray(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceEngineeringModelSetupIid", sourceEngineeringModelSetupIid => new JValue(sourceEngineeringModelSetupIid) }, - { "studyPhase", studyPhase => new JValue(studyPhase.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelSetup engineeringModelSetup) - { - var jsonObject = new JObject(); - jsonObject.Add("activeDomain", this.PropertySerializerMap["activeDomain"](engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](engineeringModelSetup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelSetup.ClassKind))); - jsonObject.Add("defaultOrganizationalParticipant", this.PropertySerializerMap["defaultOrganizationalParticipant"](engineeringModelSetup.DefaultOrganizationalParticipant)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](engineeringModelSetup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("engineeringModelIid", this.PropertySerializerMap["engineeringModelIid"](engineeringModelSetup.EngineeringModelIid)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](engineeringModelSetup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelSetup.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](engineeringModelSetup.IterationSetup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.EngineeringModelKind), engineeringModelSetup.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelSetup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](engineeringModelSetup.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participant", this.PropertySerializerMap["participant"](engineeringModelSetup.Participant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](engineeringModelSetup.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelSetup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](engineeringModelSetup.ShortName)); - jsonObject.Add("sourceEngineeringModelSetupIid", this.PropertySerializerMap["sourceEngineeringModelSetupIid"](engineeringModelSetup.SourceEngineeringModelSetupIid)); - jsonObject.Add("studyPhase", this.PropertySerializerMap["studyPhase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.StudyPhaseKind), engineeringModelSetup.StudyPhase))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelSetup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("actor"u8); + + if(engineeringModelSetup.Actor.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var engineeringModelSetup = thing as EngineeringModelSetup; - if (engineeringModelSetup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelSetup."); - } + case "activedomain": + if(!AllowedVersionsPerProperty["activeDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("activeDomain"u8); + + if(value is IEnumerable objectListActiveDomain) + { + foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultorganizationalparticipant": + if(!AllowedVersionsPerProperty["defaultOrganizationalParticipant"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "engineeringmodeliid": + if(!AllowedVersionsPerProperty["engineeringModelIid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(engineeringModelSetup); + writer.WritePropertyName("engineeringModelIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("iterationSetup"u8); + + if(value is IEnumerable objectListIterationSetup) + { + foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + } + + writer.WriteEndArray(); + break; + case "kind": + if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((EngineeringModelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organizationalParticipant"u8); + + if(value is IEnumerable objectListOrganizationalParticipant) + { + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + } + + writer.WriteEndArray(); + break; + case "participant": + if(!AllowedVersionsPerProperty["participant"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participant"u8); + + if(value is IEnumerable objectListParticipant) + { + foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requiredRdl"u8); + + if(value is IEnumerable objectListRequiredRdl) + { + foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceengineeringmodelsetupiid": + if(!AllowedVersionsPerProperty["sourceEngineeringModelSetupIid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "studyphase": + if(!AllowedVersionsPerProperty["studyPhase"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("studyPhase"u8); + + if(value != null) + { + writer.WriteStringValue(((StudyPhaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelSetup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "activeDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOrganizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "participant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceEngineeringModelSetupIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "studyPhase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 3dbbfa83f..64c281224 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationParameterType = CDP4Common.DTO.EnumerationParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,735 @@ namespace CDP4JsonSerializer public class EnumerationParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "allowMultiSelect", allowMultiSelect => new JValue(allowMultiSelect) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueDefinition", valueDefinition => new JArray(((IEnumerable)valueDefinition).Cast().Select(x => x.ToJsonObject())) }, - }; + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EnumerationParameterType enumerationParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("allowMultiSelect", this.PropertySerializerMap["allowMultiSelect"](enumerationParameterType.AllowMultiSelect)); - jsonObject.Add("category", this.PropertySerializerMap["category"](enumerationParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](enumerationParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](enumerationParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationParameterType.ThingPreference)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](enumerationParameterType.ValueDefinition.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(enumerationParameterType.Actor.HasValue) + { + writer.WriteStringValue(enumerationParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var enumerationParameterType = thing as EnumerationParameterType; - if (enumerationParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EnumerationParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "allowmultiselect": + if(!AllowedVersionsPerProperty["allowMultiSelect"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("allowMultiSelect"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(enumerationParameterType); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "allowMultiSelect", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 7644a6b0a..ccb846988 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationValueDefinition = CDP4Common.DTO.EnumerationValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,544 @@ namespace CDP4JsonSerializer public class EnumerationValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not EnumerationValueDefinition enumerationValueDefinition) + { + throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(EnumerationValueDefinition enumerationValueDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationValueDefinition.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(enumerationValueDefinition.Actor.HasValue) + { + writer.WriteStringValue(enumerationValueDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var enumerationValueDefinition = thing as EnumerationValueDefinition; - if (enumerationValueDefinition == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EnumerationValueDefinition."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(enumerationValueDefinition); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationValueDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index d02617125..7efaec894 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExclusiveOrExpression = CDP4Common.DTO.ExclusiveOrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +51,380 @@ namespace CDP4JsonSerializer public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ExclusiveOrExpression exclusiveOrExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), exclusiveOrExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](exclusiveOrExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](exclusiveOrExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](exclusiveOrExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](exclusiveOrExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](exclusiveOrExpression.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(exclusiveOrExpression.Actor.HasValue) + { + writer.WriteStringValue(exclusiveOrExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var exclusiveOrExpression = thing as ExclusiveOrExpression; - if (exclusiveOrExpression == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ExclusiveOrExpression."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(exclusiveOrExpression); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExclusiveOrExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 2ef79b40d..111625268 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExternalIdentifierMap = CDP4Common.DTO.ExternalIdentifierMap; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,578 @@ namespace CDP4JsonSerializer public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "correspondence", correspondence => new JArray(correspondence) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalFormat", externalFormat => new JValue(externalFormat) }, - { "externalModelName", externalModelName => new JValue(externalModelName) }, - { "externalToolName", externalToolName => new JValue(externalToolName) }, - { "externalToolVersion", externalToolVersion => new JValue(externalToolVersion) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ExternalIdentifierMap externalIdentifierMap) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), externalIdentifierMap.ClassKind))); - jsonObject.Add("correspondence", this.PropertySerializerMap["correspondence"](externalIdentifierMap.Correspondence.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalFormat", this.PropertySerializerMap["externalFormat"](externalIdentifierMap.ExternalFormat)); - jsonObject.Add("externalModelName", this.PropertySerializerMap["externalModelName"](externalIdentifierMap.ExternalModelName)); - jsonObject.Add("externalToolName", this.PropertySerializerMap["externalToolName"](externalIdentifierMap.ExternalToolName)); - jsonObject.Add("externalToolVersion", this.PropertySerializerMap["externalToolVersion"](externalIdentifierMap.ExternalToolVersion)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](externalIdentifierMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](externalIdentifierMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](externalIdentifierMap.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](externalIdentifierMap.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](externalIdentifierMap.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](externalIdentifierMap.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(externalIdentifierMap.Actor.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if(externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var externalIdentifierMap = thing as ExternalIdentifierMap; - if (externalIdentifierMap == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ExternalIdentifierMap."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "correspondence": + if(!AllowedVersionsPerProperty["correspondence"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("correspondence"u8); + + if(value is IEnumerable objectListCorrespondence) + { + foreach(var correspondenceItem in objectListCorrespondence.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalformat": + if(!AllowedVersionsPerProperty["externalFormat"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalFormat"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externalmodelname": + if(!AllowedVersionsPerProperty["externalModelName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalModelName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolname": + if(!AllowedVersionsPerProperty["externalToolName"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(externalIdentifierMap); + writer.WritePropertyName("externalToolName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolversion": + if(!AllowedVersionsPerProperty["externalToolVersion"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalToolVersion"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExternalIdentifierMap"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "correspondence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalFormat", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalModelName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolVersion", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index d483fea95..3685cd366 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileRevision = CDP4Common.DTO.FileRevision; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,551 @@ namespace CDP4JsonSerializer public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "contentHash", contentHash => new JValue(contentHash) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(((IEnumerable)fileType).Cast().Select(x => x.ToJsonObject())) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not FileRevision fileRevision) + { + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(FileRevision fileRevision) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileRevision.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](fileRevision.ContainingFolder)); - jsonObject.Add("contentHash", this.PropertySerializerMap["contentHash"](fileRevision.ContentHash)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](fileRevision.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](fileRevision.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileRevision.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileRevision.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](fileRevision.FileType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileRevision.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileRevision.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileRevision.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileRevision.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileRevision.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileRevision.Actor.HasValue) + { + writer.WriteStringValue(fileRevision.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var fileRevision = thing as FileRevision; - if (fileRevision == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a FileRevision."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containingfolder": + if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "contenthash": + if(!AllowedVersionsPerProperty["contentHash"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("contentHash"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(fileRevision); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileRevision"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "contentHash", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 79e798a73..0de93fab2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using File = CDP4Common.DTO.File; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,525 @@ namespace CDP4JsonSerializer public class FileSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileRevision", fileRevision => new JArray(fileRevision) }, - { "iid", iid => new JValue(iid) }, - { "lockedBy", lockedBy => new JValue(lockedBy) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not File file) + { + throw new ArgumentException("The thing shall be a File", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(File file) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](file.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), file.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](file.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](file.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileRevision", this.PropertySerializerMap["fileRevision"](file.FileRevision.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](file.Iid)); - jsonObject.Add("lockedBy", this.PropertySerializerMap["lockedBy"](file.LockedBy)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](file.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](file.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](file.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](file.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(file.Actor.HasValue) + { + writer.WriteStringValue(file.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if(file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var file = thing as File; - if (file == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a File."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(file); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filerevision": + if(!AllowedVersionsPerProperty["fileRevision"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileRevision"u8); + + if(value is IEnumerable objectListFileRevision) + { + foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lockedby": + if(!AllowedVersionsPerProperty["lockedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lockedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the File"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileRevision", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lockedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 9ace1b27f..abb0ef315 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileType = CDP4Common.DTO.FileType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class FileTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "extension", extension => new JValue(extension) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not FileType fileType) + { + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(FileType fileType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](fileType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](fileType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](fileType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("extension", this.PropertySerializerMap["extension"](fileType.Extension)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](fileType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](fileType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](fileType.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(fileType.Actor.HasValue) + { + writer.WriteStringValue(fileType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var fileType = thing as FileType; - if (fileType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a FileType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(fileType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "extension": + if(!AllowedVersionsPerProperty["extension"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("extension"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "extension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 4c1ce3094..084799a73 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Folder = CDP4Common.DTO.Folder; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,496 @@ namespace CDP4JsonSerializer public class FolderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Folder folder) + { + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Folder folder) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), folder.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](folder.ContainingFolder)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](folder.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](folder.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](folder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](folder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](folder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](folder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](folder.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](folder.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](folder.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](folder.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(folder.Actor.HasValue) + { + writer.WriteStringValue(folder.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if(folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var folder = thing as Folder; - if (folder == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Folder."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containingfolder": + if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(folder); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Folder"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index 6318bc35b..8574105e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Glossary = CDP4Common.DTO.Glossary; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,681 @@ namespace CDP4JsonSerializer public class GlossarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Glossary glossary) + { + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Glossary glossary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](glossary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](glossary.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), glossary.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](glossary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](glossary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](glossary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](glossary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](glossary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](glossary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](glossary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](glossary.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](glossary.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](glossary.ShortName)); - jsonObject.Add("term", this.PropertySerializerMap["term"](glossary.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](glossary.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(glossary.Actor.HasValue) + { + writer.WriteStringValue(glossary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var glossary = thing as Glossary; - if (glossary == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Glossary."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(glossary); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Glossary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 0e9904633..0fa9e943c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Goal = CDP4Common.DTO.Goal; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,550 @@ namespace CDP4JsonSerializer public class GoalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Goal goal) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](goal.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](goal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), goal.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](goal.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](goal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](goal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](goal.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](goal.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](goal.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](goal.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](goal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](goal.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](goal.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(goal.Actor.HasValue) + { + writer.WriteStringValue(goal.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var goal = thing as Goal; - if (goal == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Goal."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(goal); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Goal"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 3a34e9acd..d8d7d1034 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using HyperLink = CDP4Common.DTO.HyperLink; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "uri", uri => new JValue(uri) }, - }; + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(HyperLink hyperLink) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), hyperLink.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](hyperLink.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](hyperLink.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](hyperLink.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](hyperLink.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](hyperLink.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](hyperLink.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](hyperLink.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](hyperLink.ThingPreference)); - jsonObject.Add("uri", this.PropertySerializerMap["uri"](hyperLink.Uri)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(hyperLink.Actor.HasValue) + { + writer.WriteStringValue(hyperLink.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var hyperLink = thing as HyperLink; - if (hyperLink == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a HyperLink."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(hyperLink); + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "uri": + if(!AllowedVersionsPerProperty["uri"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("uri"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the HyperLink"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "uri", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index 70bfb8a60..2c602e0b1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IdCorrespondence = CDP4Common.DTO.IdCorrespondence; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalId", externalId => new JValue(externalId) }, - { "iid", iid => new JValue(iid) }, - { "internalThing", internalThing => new JValue(internalThing) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not IdCorrespondence idCorrespondence) + { + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IdCorrespondence idCorrespondence) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), idCorrespondence.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](idCorrespondence.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](idCorrespondence.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalId", this.PropertySerializerMap["externalId"](idCorrespondence.ExternalId)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](idCorrespondence.Iid)); - jsonObject.Add("internalThing", this.PropertySerializerMap["internalThing"](idCorrespondence.InternalThing)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](idCorrespondence.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](idCorrespondence.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](idCorrespondence.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(idCorrespondence.Actor.HasValue) + { + writer.WriteStringValue(idCorrespondence.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var idCorrespondence = thing as IdCorrespondence; - if (idCorrespondence == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IdCorrespondence."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalid": + if(!AllowedVersionsPerProperty["externalId"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("externalId"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(idCorrespondence); + break; + case "internalthing": + if(!AllowedVersionsPerProperty["internalThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("internalThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IdCorrespondence"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalId", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "internalThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index f836203f0..0ba05cad9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IndependentParameterTypeAssignment = CDP4Common.DTO.IndependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,351 @@ namespace CDP4JsonSerializer public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IndependentParameterTypeAssignment independentParameterTypeAssignment) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), independentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](independentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](independentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](independentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](independentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](independentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](independentParameterTypeAssignment.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(independentParameterTypeAssignment.Actor.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if(independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var independentParameterTypeAssignment = thing as IndependentParameterTypeAssignment; - if (independentParameterTypeAssignment == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IndependentParameterTypeAssignment."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(independentParameterTypeAssignment); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IndependentParameterTypeAssignment"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 0304f4c72..6fa8d528c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IntervalScale = CDP4Common.DTO.IntervalScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +51,897 @@ namespace CDP4JsonSerializer public class IntervalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + if (thing is not IntervalScale intervalScale) + { + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IntervalScale intervalScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](intervalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), intervalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](intervalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](intervalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](intervalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](intervalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](intervalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](intervalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](intervalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](intervalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](intervalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](intervalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](intervalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](intervalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](intervalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](intervalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), intervalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](intervalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](intervalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](intervalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](intervalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](intervalScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](intervalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(intervalScale.Actor.HasValue) + { + writer.WriteStringValue(intervalScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var intervalScale = thing as IntervalScale; - if (intervalScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IntervalScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(intervalScale); + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index a5a4ed411..09ac4f3a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Iteration = CDP4Common.DTO.Iteration; /// /// The purpose of the class is to provide a specific serializer @@ -45,108 +51,1413 @@ namespace CDP4JsonSerializer public class IterationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualFiniteStateList", actualFiniteStateList => new JArray(actualFiniteStateList) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOption", defaultOption => new JValue(defaultOption) }, - { "diagramCanvas", diagramCanvas => new JArray(diagramCanvas) }, - { "domainFileStore", domainFileStore => new JArray(domainFileStore) }, - { "element", element => new JArray(element) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalIdentifierMap", externalIdentifierMap => new JArray(externalIdentifierMap) }, - { "goal", goal => new JArray(goal) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JValue(iterationSetup) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "option", option => new JArray(((IEnumerable)option).Cast().Select(x => x.ToJsonObject())) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(possibleFiniteStateList) }, - { "publication", publication => new JArray(publication) }, - { "relationship", relationship => new JArray(relationship) }, - { "requirementsSpecification", requirementsSpecification => new JArray(requirementsSpecification) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerificationList", ruleVerificationList => new JArray(ruleVerificationList) }, - { "sharedDiagramStyle", sharedDiagramStyle => new JArray(sharedDiagramStyle) }, - { "sourceIterationIid", sourceIterationIid => new JValue(sourceIterationIid) }, - { "stakeholder", stakeholder => new JArray(stakeholder) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "stakeholderValueMap", stakeholderValueMap => new JArray(stakeholderValueMap) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topElement", topElement => new JValue(topElement) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + if (thing is not Iteration iteration) + { + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Iteration iteration) - { - var jsonObject = new JObject(); - jsonObject.Add("actualFiniteStateList", this.PropertySerializerMap["actualFiniteStateList"](iteration.ActualFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iteration.ClassKind))); - jsonObject.Add("defaultOption", this.PropertySerializerMap["defaultOption"](iteration.DefaultOption)); - jsonObject.Add("diagramCanvas", this.PropertySerializerMap["diagramCanvas"](iteration.DiagramCanvas.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainFileStore", this.PropertySerializerMap["domainFileStore"](iteration.DomainFileStore.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("element", this.PropertySerializerMap["element"](iteration.Element.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iteration.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iteration.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalIdentifierMap", this.PropertySerializerMap["externalIdentifierMap"](iteration.ExternalIdentifierMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](iteration.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iteration.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](iteration.IterationSetup)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iteration.ModifiedOn)); - jsonObject.Add("option", this.PropertySerializerMap["option"](iteration.Option.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](iteration.PossibleFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("publication", this.PropertySerializerMap["publication"](iteration.Publication.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationship", this.PropertySerializerMap["relationship"](iteration.Relationship.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirementsSpecification", this.PropertySerializerMap["requirementsSpecification"](iteration.RequirementsSpecification.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iteration.RevisionNumber)); - jsonObject.Add("ruleVerificationList", this.PropertySerializerMap["ruleVerificationList"](iteration.RuleVerificationList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sharedDiagramStyle", this.PropertySerializerMap["sharedDiagramStyle"](iteration.SharedDiagramStyle.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sourceIterationIid", this.PropertySerializerMap["sourceIterationIid"](iteration.SourceIterationIid)); - jsonObject.Add("stakeholder", this.PropertySerializerMap["stakeholder"](iteration.Stakeholder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](iteration.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValueMap", this.PropertySerializerMap["stakeholderValueMap"](iteration.StakeholderValueMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iteration.ThingPreference)); - jsonObject.Add("topElement", this.PropertySerializerMap["topElement"](iteration.TopElement)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](iteration.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(iteration.Actor.HasValue) + { + writer.WriteStringValue(iteration.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if(iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if(iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if(iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var iteration = thing as Iteration; - if (iteration == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Iteration."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualfinitestatelist": + if(!AllowedVersionsPerProperty["actualFiniteStateList"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("actualFiniteStateList"u8); - return this.Serialize(iteration); + if(value is IEnumerable objectListActualFiniteStateList) + { + foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultoption": + if(!AllowedVersionsPerProperty["defaultOption"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramcanvas": + if(!AllowedVersionsPerProperty["diagramCanvas"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("diagramCanvas"u8); + + if(value is IEnumerable objectListDiagramCanvas) + { + foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + } + + writer.WriteEndArray(); + break; + case "domainfilestore": + if(!AllowedVersionsPerProperty["domainFileStore"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domainFileStore"u8); + + if(value is IEnumerable objectListDomainFileStore) + { + foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + } + + writer.WriteEndArray(); + break; + case "element": + if(!AllowedVersionsPerProperty["element"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("element"u8); + + if(value is IEnumerable objectListElement) + { + foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "externalidentifiermap": + if(!AllowedVersionsPerProperty["externalIdentifierMap"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("externalIdentifierMap"u8); + + if(value is IEnumerable objectListExternalIdentifierMap) + { + foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + } + + writer.WriteEndArray(); + break; + case "goal": + if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("goal"u8); + + if(value is IEnumerable objectListGoal) + { + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "option": + if(!AllowedVersionsPerProperty["option"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("option"u8); + + if(value is IEnumerable objectListOption) + { + foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + } + + writer.WriteEndArray(); + break; + case "possiblefinitestatelist": + if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleFiniteStateList"u8); + + if(value is IEnumerable objectListPossibleFiniteStateList) + { + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + } + + writer.WriteEndArray(); + break; + case "publication": + if(!AllowedVersionsPerProperty["publication"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("publication"u8); + + if(value is IEnumerable objectListPublication) + { + foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + } + + writer.WriteEndArray(); + break; + case "relationship": + if(!AllowedVersionsPerProperty["relationship"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relationship"u8); + + if(value is IEnumerable objectListRelationship) + { + foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + } + + writer.WriteEndArray(); + break; + case "requirementsspecification": + if(!AllowedVersionsPerProperty["requirementsSpecification"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirementsSpecification"u8); + + if(value is IEnumerable objectListRequirementsSpecification) + { + foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverificationlist": + if(!AllowedVersionsPerProperty["ruleVerificationList"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("ruleVerificationList"u8); + + if(value is IEnumerable objectListRuleVerificationList) + { + foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + } + + writer.WriteEndArray(); + break; + case "shareddiagramstyle": + if(!AllowedVersionsPerProperty["sharedDiagramStyle"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sharedDiagramStyle"u8); + + if(value is IEnumerable objectListSharedDiagramStyle) + { + foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + } + + writer.WriteEndArray(); + break; + case "sourceiterationiid": + if(!AllowedVersionsPerProperty["sourceIterationIid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceIterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholder": + if(!AllowedVersionsPerProperty["stakeholder"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholder"u8); + + if(value is IEnumerable objectListStakeholder) + { + foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + } + + writer.WriteEndArray(); + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "stakeholdervaluemap": + if(!AllowedVersionsPerProperty["stakeholderValueMap"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValueMap"u8); + + if(value is IEnumerable objectListStakeholderValueMap) + { + foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topelement": + if(!AllowedVersionsPerProperty["topElement"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("topElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueGroup"u8); + + if(value is IEnumerable objectListValueGroup) + { + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramCanvas", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "domainFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "element", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalIdentifierMap", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "option", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publication", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationship", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requirementsSpecification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerificationList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedDiagramStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholder", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueMap", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index ee7be73e7..ade206847 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IterationSetup = CDP4Common.DTO.IterationSetup; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,586 @@ namespace CDP4JsonSerializer public class IterationSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "frozenOn", frozenOn => new JValue(frozenOn != null ? ((DateTime)frozenOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isDeleted", isDeleted => new JValue(isDeleted) }, - { "iterationIid", iterationIid => new JValue(iterationIid) }, - { "iterationNumber", iterationNumber => new JValue(iterationNumber) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sourceIterationSetup", sourceIterationSetup => new JValue(sourceIterationSetup) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(IterationSetup iterationSetup) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iterationSetup.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](iterationSetup.CreatedOn)); - jsonObject.Add("description", this.PropertySerializerMap["description"](iterationSetup.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iterationSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iterationSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("frozenOn", this.PropertySerializerMap["frozenOn"](iterationSetup.FrozenOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iterationSetup.Iid)); - jsonObject.Add("isDeleted", this.PropertySerializerMap["isDeleted"](iterationSetup.IsDeleted)); - jsonObject.Add("iterationIid", this.PropertySerializerMap["iterationIid"](iterationSetup.IterationIid)); - jsonObject.Add("iterationNumber", this.PropertySerializerMap["iterationNumber"](iterationSetup.IterationNumber)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iterationSetup.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iterationSetup.RevisionNumber)); - jsonObject.Add("sourceIterationSetup", this.PropertySerializerMap["sourceIterationSetup"](iterationSetup.SourceIterationSetup)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iterationSetup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(iterationSetup.Actor.HasValue) + { + writer.WriteStringValue(iterationSetup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if(iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if(iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var iterationSetup = thing as IterationSetup; - if (iterationSetup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IterationSetup."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "frozenon": + if(!AllowedVersionsPerProperty["frozenOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("frozenOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(iterationSetup); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeleted": + if(!AllowedVersionsPerProperty["isDeleted"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeleted"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationiid": + if(!AllowedVersionsPerProperty["iterationIid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationnumber": + if(!AllowedVersionsPerProperty["iterationNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iterationNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceiterationsetup": + if(!AllowedVersionsPerProperty["sourceIterationSetup"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("sourceIterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IterationSetup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "frozenOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeleted", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 1f6be53f3..6a462edc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LinearConversionUnit = CDP4Common.DTO.LinearConversionUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,625 @@ namespace CDP4JsonSerializer public class LinearConversionUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not LinearConversionUnit linearConversionUnit) + { + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LinearConversionUnit linearConversionUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](linearConversionUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), linearConversionUnit.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](linearConversionUnit.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](linearConversionUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](linearConversionUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](linearConversionUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](linearConversionUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](linearConversionUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](linearConversionUnit.Name)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](linearConversionUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](linearConversionUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](linearConversionUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](linearConversionUnit.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(linearConversionUnit.Actor.HasValue) + { + writer.WriteStringValue(linearConversionUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var linearConversionUnit = thing as LinearConversionUnit; - if (linearConversionUnit == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LinearConversionUnit."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(linearConversionUnit); + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LinearConversionUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index 334db2960..b6919f1eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogEntryChangelogItem = CDP4Common.DTO.LogEntryChangelogItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,393 @@ namespace CDP4JsonSerializer public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedItemIid", affectedItemIid => new JValue(affectedItemIid) }, - { "affectedReferenceIid", affectedReferenceIid => new JArray(affectedReferenceIid) }, - { "changeDescription", changeDescription => new JValue(changeDescription) }, - { "changelogKind", changelogKind => new JValue(changelogKind.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not LogEntryChangelogItem logEntryChangelogItem) + { + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LogEntryChangelogItem logEntryChangelogItem) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](logEntryChangelogItem.AffectedItemIid)); - jsonObject.Add("affectedReferenceIid", this.PropertySerializerMap["affectedReferenceIid"](logEntryChangelogItem.AffectedReferenceIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeDescription", this.PropertySerializerMap["changeDescription"](logEntryChangelogItem.ChangeDescription)); - jsonObject.Add("changelogKind", this.PropertySerializerMap["changelogKind"](Enum.GetName(typeof(CDP4Common.CommonData.LogEntryChangelogItemKind), logEntryChangelogItem.ChangelogKind))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logEntryChangelogItem.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logEntryChangelogItem.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logEntryChangelogItem.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logEntryChangelogItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logEntryChangelogItem.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.2.0"); + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logEntryChangelogItem.Actor.HasValue) + { + writer.WriteStringValue(logEntryChangelogItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var logEntryChangelogItem = thing as LogEntryChangelogItem; - if (logEntryChangelogItem == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LogEntryChangelogItem."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteditemiid": + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("affectedItemIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affectedreferenceiid": + if(!AllowedVersionsPerProperty["affectedReferenceIid"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedReferenceIid"u8); + + if(value is IEnumerable objectListAffectedReferenceIid) + { + foreach(var affectedReferenceIidItem in objectListAffectedReferenceIid) + { + writer.WriteStringValue((Guid)affectedReferenceIidItem); + } + } + + writer.WriteEndArray(); + break; + case "changedescription": + if(!AllowedVersionsPerProperty["changeDescription"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changeDescription"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "changelogkind": + if(!AllowedVersionsPerProperty["changelogKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("changelogKind"u8); + + if(value != null) + { + writer.WriteStringValue(((LogEntryChangelogItemKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(logEntryChangelogItem); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogEntryChangelogItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedItemIid", new []{ "1.2.0", "1.3.0" }}, + { "affectedReferenceIid", new []{ "1.2.0", "1.3.0" }}, + { "changeDescription", new []{ "1.2.0", "1.3.0" }}, + { "changelogKind", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index e25bd97c4..04e2d9987 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogarithmicScale = CDP4Common.DTO.LogarithmicScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,108 +51,1060 @@ namespace CDP4JsonSerializer public class LogarithmicScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "factor", factor => new JValue(factor) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "logarithmBase", logarithmBase => new JValue(logarithmBase.ToString()) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "referenceQuantityKind", referenceQuantityKind => new JValue(referenceQuantityKind) }, - { "referenceQuantityValue", referenceQuantityValue => new JArray(referenceQuantityValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(LogarithmicScale logarithmicScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](logarithmicScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logarithmicScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](logarithmicScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logarithmicScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logarithmicScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](logarithmicScale.Exponent)); - jsonObject.Add("factor", this.PropertySerializerMap["factor"](logarithmicScale.Factor)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](logarithmicScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logarithmicScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](logarithmicScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](logarithmicScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](logarithmicScale.IsMinimumInclusive)); - jsonObject.Add("logarithmBase", this.PropertySerializerMap["logarithmBase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.LogarithmBaseKind), logarithmicScale.LogarithmBase))); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](logarithmicScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](logarithmicScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logarithmicScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](logarithmicScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](logarithmicScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), logarithmicScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](logarithmicScale.PositiveValueConnotation)); - jsonObject.Add("referenceQuantityKind", this.PropertySerializerMap["referenceQuantityKind"](logarithmicScale.ReferenceQuantityKind)); - jsonObject.Add("referenceQuantityValue", this.PropertySerializerMap["referenceQuantityValue"](logarithmicScale.ReferenceQuantityValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logarithmicScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](logarithmicScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logarithmicScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](logarithmicScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](logarithmicScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(logarithmicScale.Actor.HasValue) + { + writer.WriteStringValue(logarithmicScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var logarithmicScale = thing as LogarithmicScale; - if (logarithmicScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LogarithmicScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "factor": + if(!AllowedVersionsPerProperty["factor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("factor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logarithmbase": + if(!AllowedVersionsPerProperty["logarithmBase"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("logarithmBase"u8); + + if(value != null) + { + writer.WriteStringValue(((LogarithmBaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(logarithmicScale); + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantitykind": + if(!AllowedVersionsPerProperty["referenceQuantityKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceQuantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantityvalue": + if(!AllowedVersionsPerProperty["referenceQuantityValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceQuantityValue"u8); + + if(value is IEnumerable objectListReferenceQuantityValue) + { + foreach(var referenceQuantityValueItem in objectListReferenceQuantityValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogarithmicScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "factor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logarithmBase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index d2fcf1775..4514063da 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MappingToReferenceScale = CDP4Common.DTO.MappingToReferenceScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "dependentScaleValue", dependentScaleValue => new JValue(dependentScaleValue) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referenceScaleValue", referenceScaleValue => new JValue(referenceScaleValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not MappingToReferenceScale mappingToReferenceScale) + { + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MappingToReferenceScale mappingToReferenceScale) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), mappingToReferenceScale.ClassKind))); - jsonObject.Add("dependentScaleValue", this.PropertySerializerMap["dependentScaleValue"](mappingToReferenceScale.DependentScaleValue)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](mappingToReferenceScale.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](mappingToReferenceScale.ModifiedOn)); - jsonObject.Add("referenceScaleValue", this.PropertySerializerMap["referenceScaleValue"](mappingToReferenceScale.ReferenceScaleValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](mappingToReferenceScale.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](mappingToReferenceScale.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(mappingToReferenceScale.Actor.HasValue) + { + writer.WriteStringValue(mappingToReferenceScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var mappingToReferenceScale = thing as MappingToReferenceScale; - if (mappingToReferenceScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MappingToReferenceScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "dependentscalevalue": + if(!AllowedVersionsPerProperty["dependentScaleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("dependentScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(mappingToReferenceScale); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencescalevalue": + if(!AllowedVersionsPerProperty["referenceScaleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MappingToReferenceScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dependentScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index e3f2927ba..e2775bf9a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelLogEntry = CDP4Common.DTO.ModelLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,698 @@ namespace CDP4JsonSerializer public class ModelLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModelLogEntry modelLogEntry) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](modelLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](modelLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](modelLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](modelLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](modelLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](modelLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](modelLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), modelLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelLogEntry.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelLogEntry.Actor.HasValue) + { + writer.WriteStringValue(modelLogEntry.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var modelLogEntry = thing as ModelLogEntry; - if (modelLogEntry == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModelLogEntry."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteddomainiid": + if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) + { + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + } + + writer.WriteEndArray(); + break; + case "affecteditemiid": + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedItemIid"u8); + + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(modelLogEntry); + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntryChangelogItem"u8); + + if(value is IEnumerable objectListLogEntryChangelogItem) + { + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelLogEntry"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 89b20d876..eb5656fcc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelReferenceDataLibrary = CDP4Common.DTO.ModelReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -45,102 +51,1267 @@ namespace CDP4JsonSerializer public class ModelReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModelReferenceDataLibrary modelReferenceDataLibrary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](modelReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](modelReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](modelReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](modelReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelReferenceDataLibrary.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](modelReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](modelReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](modelReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](modelReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](modelReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](modelReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modelReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var modelReferenceDataLibrary = thing as ModelReferenceDataLibrary; - if (modelReferenceDataLibrary == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModelReferenceDataLibrary."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); - return this.Serialize(modelReferenceDataLibrary); + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "basequantitykind": + if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseQuantityKind"u8); + + if(value is IEnumerable objectListBaseQuantityKind) + { + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + } + + writer.WriteEndArray(); + break; + case "baseunit": + if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseUnit"u8); + + if(value is IEnumerable objectListBaseUnit) + { + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + + writer.WriteEndArray(); + break; + case "definedcategory": + if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definedCategory"u8); + + if(value is IEnumerable objectListDefinedCategory) + { + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "glossary": + if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("glossary"u8); + + if(value is IEnumerable objectListGlossary) + { + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "referencesource": + if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceSource"u8); + + if(value is IEnumerable objectListReferenceSource) + { + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("rule"u8); + + if(value is IEnumerable objectListRule) + { + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + } + + writer.WriteEndArray(); + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("scale"u8); + + if(value is IEnumerable objectListScale) + { + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unit"u8); + + if(value is IEnumerable objectListUnit) + { + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + } + + writer.WriteEndArray(); + break; + case "unitprefix": + if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitPrefix"u8); + + if(value is IEnumerable objectListUnitPrefix) + { + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 2c4de11f9..f2c660d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModellingThingReference = CDP4Common.DTO.ModellingThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,366 @@ namespace CDP4JsonSerializer public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ModellingThingReference modellingThingReference) + { + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ModellingThingReference modellingThingReference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modellingThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modellingThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modellingThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modellingThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modellingThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](modellingThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](modellingThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modellingThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modellingThingReference.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(modellingThingReference.Actor.HasValue) + { + writer.WriteStringValue(modellingThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var modellingThingReference = thing as ModellingThingReference; - if (modellingThingReference == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModellingThingReference."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(modellingThingReference); + break; + case "referencedrevisionnumber": + if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModellingThingReference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index c863de8e8..b16ada893 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationshipRule = CDP4Common.DTO.MultiRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,707 @@ namespace CDP4JsonSerializer public class MultiRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxRelated", maxRelated => new JValue(maxRelated) }, - { "minRelated", minRelated => new JValue(minRelated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relatedCategory", relatedCategory => new JArray(relatedCategory) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationshipRule multiRelationshipRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](multiRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](multiRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](multiRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationshipRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](multiRelationshipRule.IsDeprecated)); - jsonObject.Add("maxRelated", this.PropertySerializerMap["maxRelated"](multiRelationshipRule.MaxRelated)); - jsonObject.Add("minRelated", this.PropertySerializerMap["minRelated"](multiRelationshipRule.MinRelated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationshipRule.Name)); - jsonObject.Add("relatedCategory", this.PropertySerializerMap["relatedCategory"](multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](multiRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](multiRelationshipRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationshipRule.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationshipRule.Actor.HasValue) + { + writer.WriteStringValue(multiRelationshipRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var multiRelationshipRule = thing as MultiRelationshipRule; - if (multiRelationshipRule == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MultiRelationshipRule."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(multiRelationshipRule); + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxrelated": + if(!AllowedVersionsPerProperty["maxRelated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minrelated": + if(!AllowedVersionsPerProperty["minRelated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedcategory": + if(!AllowedVersionsPerProperty["relatedCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedCategory"u8); + + if(value is IEnumerable objectListRelatedCategory) + { + foreach(var relatedCategoryItem in objectListRelatedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "relationshipcategory": + if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationshipRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 42be8c406..a32f0b238 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationship = CDP4Common.DTO.MultiRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,531 @@ namespace CDP4JsonSerializer public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not MultiRelationship multiRelationship) + { + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationship multiRelationship) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](multiRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](multiRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](multiRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](multiRelationship.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationship.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationship.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(multiRelationship.Actor.HasValue) + { + writer.WriteStringValue(multiRelationship.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var multiRelationship = thing as MultiRelationship; - if (multiRelationship == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MultiRelationship."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(multiRelationship); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationship"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index 2b50c8de3..f609812ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NaturalLanguage = CDP4Common.DTO.NaturalLanguage; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nativeName", nativeName => new JValue(nativeName) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NaturalLanguage naturalLanguage) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), naturalLanguage.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](naturalLanguage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](naturalLanguage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](naturalLanguage.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](naturalLanguage.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](naturalLanguage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](naturalLanguage.Name)); - jsonObject.Add("nativeName", this.PropertySerializerMap["nativeName"](naturalLanguage.NativeName)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](naturalLanguage.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](naturalLanguage.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(naturalLanguage.Actor.HasValue) + { + writer.WriteStringValue(naturalLanguage.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var naturalLanguage = thing as NaturalLanguage; - if (naturalLanguage == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NaturalLanguage."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(naturalLanguage); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nativename": + if(!AllowedVersionsPerProperty["nativeName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("nativeName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NaturalLanguage"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nativeName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 2128e2ef7..ec17d25b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedElement = CDP4Common.DTO.NestedElement; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,489 @@ namespace CDP4JsonSerializer public class NestedElementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "elementUsage", elementUsage => new JArray(((IEnumerable)elementUsage).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "nestedParameter", nestedParameter => new JArray(nestedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rootElement", rootElement => new JValue(rootElement) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not NestedElement nestedElement) + { + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NestedElement nestedElement) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedElement.ClassKind))); - jsonObject.Add("elementUsage", this.PropertySerializerMap["elementUsage"](nestedElement.ElementUsage.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedElement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedElement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedElement.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedElement.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedElement.ModifiedOn)); - jsonObject.Add("nestedParameter", this.PropertySerializerMap["nestedParameter"](nestedElement.NestedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedElement.RevisionNumber)); - jsonObject.Add("rootElement", this.PropertySerializerMap["rootElement"](nestedElement.RootElement)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedElement.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedElement.Actor.HasValue) + { + writer.WriteStringValue(nestedElement.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var nestedElement = thing as NestedElement; - if (nestedElement == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NestedElement."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "elementusage": + if(!AllowedVersionsPerProperty["elementUsage"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("elementUsage"u8); + + if(value is IEnumerable objectListElementUsage) + { + foreach(var elementUsageItem in objectListElementUsage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(nestedElement); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nestedparameter": + if(!AllowedVersionsPerProperty["nestedParameter"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("nestedParameter"u8); + + if(value is IEnumerable objectListNestedParameter) + { + foreach(var nestedParameterItem in objectListNestedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rootelement": + if(!AllowedVersionsPerProperty["rootElement"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("rootElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedElement"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementUsage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rootElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index e887dc06d..ead620444 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedParameter = CDP4Common.DTO.NestedParameter; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,523 @@ namespace CDP4JsonSerializer public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JValue(actualState) }, - { "actualValue", actualValue => new JValue(actualValue) }, - { "associatedParameter", associatedParameter => new JValue(associatedParameter) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(formula) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not NestedParameter nestedParameter) + { + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NestedParameter nestedParameter) - { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](nestedParameter.ActualState)); - jsonObject.Add("actualValue", this.PropertySerializerMap["actualValue"](nestedParameter.ActualValue)); - jsonObject.Add("associatedParameter", this.PropertySerializerMap["associatedParameter"](nestedParameter.AssociatedParameter)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedParameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedParameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedParameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](nestedParameter.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedParameter.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedParameter.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedParameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](nestedParameter.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedParameter.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedParameter.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.0.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.1.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.2.0"); + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(nestedParameter.Actor.HasValue) + { + writer.WriteStringValue(nestedParameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var nestedParameter = thing as NestedParameter; - if (nestedParameter == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NestedParameter."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualvalue": + if(!AllowedVersionsPerProperty["actualValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "associatedparameter": + if(!AllowedVersionsPerProperty["associatedParameter"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("associatedParameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("formula"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(nestedParameter); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedParameter"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "associatedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 274f67880..31a6ead32 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NotExpression = CDP4Common.DTO.NotExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +51,352 @@ namespace CDP4JsonSerializer public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JValue(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not NotExpression notExpression) + { + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(NotExpression notExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), notExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](notExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](notExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](notExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](notExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](notExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](notExpression.Term)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](notExpression.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(notExpression.Actor.HasValue) + { + writer.WriteStringValue(notExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var notExpression = thing as NotExpression; - if (notExpression == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NotExpression."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(notExpression); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("term"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NotExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 617b5d033..7090d29fd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Option = CDP4Common.DTO.Option; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,654 @@ namespace CDP4JsonSerializer public class OptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nestedElement", nestedElement => new JArray(nestedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Option option) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](option.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](option.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), option.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](option.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](option.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](option.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](option.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](option.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](option.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](option.Name)); - jsonObject.Add("nestedElement", this.PropertySerializerMap["nestedElement"](option.NestedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](option.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](option.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](option.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(option.Actor.HasValue) + { + writer.WriteStringValue(option.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var option = thing as Option; - if (option == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Option."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(option); + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nestedelement": + if(!AllowedVersionsPerProperty["nestedElement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("nestedElement"u8); + + if(value is IEnumerable objectListNestedElement) + { + foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Option"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index 18bd07fd6..5cd8ddfb5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrExpression = CDP4Common.DTO.OrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +51,380 @@ namespace CDP4JsonSerializer public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrExpression orExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), orExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](orExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](orExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](orExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](orExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](orExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](orExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](orExpression.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(orExpression.Actor.HasValue) + { + writer.WriteStringValue(orExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var orExpression = thing as OrExpression; - if (orExpression == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrExpression."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(orExpression); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("term"u8); + + if(value is IEnumerable objectListTerm) + { + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 88c02416e..33ee7da57 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrdinalScale = CDP4Common.DTO.OrdinalScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +51,924 @@ namespace CDP4JsonSerializer public class OrdinalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "useShortNameValues", useShortNameValues => new JValue(useShortNameValues) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + if (thing is not OrdinalScale ordinalScale) + { + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrdinalScale ordinalScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ordinalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ordinalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ordinalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ordinalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ordinalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ordinalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ordinalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ordinalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ordinalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ordinalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ordinalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ordinalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ordinalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ordinalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ordinalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ordinalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ordinalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ordinalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ordinalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ordinalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ordinalScale.Unit)); - jsonObject.Add("useShortNameValues", this.PropertySerializerMap["useShortNameValues"](ordinalScale.UseShortNameValues)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ordinalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ordinalScale.Actor.HasValue) + { + writer.WriteStringValue(ordinalScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var ordinalScale = thing as OrdinalScale; - if (ordinalScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrdinalScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("mappingToReferenceScale"u8); - return this.Serialize(ordinalScale); + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "useshortnamevalues": + if(!AllowedVersionsPerProperty["useShortNameValues"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("useShortNameValues"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrdinalScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "useShortNameValues", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 8e79f2781..5c96221c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Organization = CDP4Common.DTO.Organization; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class OrganizationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Organization organization) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organization.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organization.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organization.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organization.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](organization.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organization.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](organization.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organization.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](organization.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organization.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organization.Actor.HasValue) + { + writer.WriteStringValue(organization.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var organization = thing as Organization; - if (organization == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Organization."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(organization); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Organization"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 90998e961..cddea0cef 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrganizationalParticipant = CDP4Common.DTO.OrganizationalParticipant; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +51,310 @@ namespace CDP4JsonSerializer public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not OrganizationalParticipant organizationalParticipant) + { + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OrganizationalParticipant organizationalParticipant) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organizationalParticipant.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organizationalParticipant.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organizationalParticipant.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](organizationalParticipant.Organization)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organizationalParticipant.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organizationalParticipant.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(organizationalParticipant.Actor.HasValue) + { + writer.WriteStringValue(organizationalParticipant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var organizationalParticipant = thing as OrganizationalParticipant; - if (organizationalParticipant == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrganizationalParticipant."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(organizationalParticipant); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrganizationalParticipant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 1ecec9d6e..a85d891e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OwnedStyle = CDP4Common.DTO.OwnedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +51,984 @@ namespace CDP4JsonSerializer public class OwnedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + if (thing is not OwnedStyle ownedStyle) + { + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(OwnedStyle ownedStyle) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ownedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ownedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ownedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](ownedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](ownedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](ownedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](ownedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](ownedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](ownedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](ownedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](ownedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](ownedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ownedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ownedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ownedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ownedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](ownedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](ownedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](ownedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ownedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](ownedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ownedStyle.Actor.HasValue) + { + writer.WriteStringValue(ownedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var ownedStyle = thing as OwnedStyle; - if (ownedStyle == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OwnedStyle."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(ownedStyle); + break; + case "fontbold": + if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontitalic": + if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("usedColor"u8); + + if(value is IEnumerable objectListUsedColor) + { + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index 13aff4683..d2820f39d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Page = CDP4Common.DTO.Page; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,508 @@ namespace CDP4JsonSerializer public class PageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Page page) + { + throw new ArgumentException("The thing shall be a Page", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Page page) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](page.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), page.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](page.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](page.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](page.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](page.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](page.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](page.Name)); - jsonObject.Add("note", this.PropertySerializerMap["note"](page.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](page.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](page.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](page.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](page.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(page.Actor.HasValue) + { + writer.WriteStringValue(page.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var page = thing as Page; - if (page == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Page."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(page); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("note"u8); + + if(value is IEnumerable objectListNote) + { + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + } + + writer.WriteEndArray(); + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Page"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index bdf558c4c..81f5146b0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterGroup = CDP4Common.DTO.ParameterGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,415 @@ namespace CDP4JsonSerializer public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingGroup", containingGroup => new JValue(containingGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterGroup parameterGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterGroup.ClassKind))); - jsonObject.Add("containingGroup", this.PropertySerializerMap["containingGroup"](parameterGroup.ContainingGroup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterGroup.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterGroup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterGroup.Actor.HasValue) + { + writer.WriteStringValue(parameterGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if(parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterGroup = thing as ParameterGroup; - if (parameterGroup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterGroup."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containinggroup": + if(!AllowedVersionsPerProperty["containingGroup"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("containingGroup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(parameterGroup); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 9ae30cfd9..c3be67cda 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverride = CDP4Common.DTO.ParameterOverride; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,489 @@ namespace CDP4JsonSerializer public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JValue(parameter) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + if (thing is not ParameterOverride parameterOverride) + { + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverride parameterOverride) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverride.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverride.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverride.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverride.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverride.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterOverride.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](parameterOverride.Parameter)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameterOverride.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverride.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverride.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterOverride.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverride.Actor.HasValue) + { + writer.WriteStringValue(parameterOverride.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterOverride = thing as ParameterOverride; - if (parameterOverride == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterOverride."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(parameterOverride); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterSubscription"u8); + + if(value is IEnumerable objectListParameterSubscription) + { + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverride"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index a9140eb2f..1c3b80807 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverrideValueSet = CDP4Common.DTO.ParameterOverrideValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,444 @@ namespace CDP4JsonSerializer public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterValueSet", parameterValueSet => new JValue(parameterValueSet) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) + { + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverrideValueSet parameterOverrideValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverrideValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterOverrideValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterOverrideValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverrideValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterOverrideValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverrideValueSet.ModifiedOn)); - jsonObject.Add("parameterValueSet", this.PropertySerializerMap["parameterValueSet"](parameterOverrideValueSet.ParameterValueSet)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterOverrideValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterOverrideValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverrideValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverrideValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterOverrideValueSet.ValueSwitch))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterOverrideValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterOverrideValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterOverrideValueSet = thing as ParameterOverrideValueSet; - if (parameterOverrideValueSet == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterOverrideValueSet."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterOverrideValueSet); + break; + case "parametervalueset": + if(!AllowedVersionsPerProperty["parameterValueSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverrideValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index 442cb4ac5..edb35c055 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Parameter = CDP4Common.DTO.Parameter; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,822 @@ namespace CDP4JsonSerializer public class ParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "allowDifferentOwnerOfOverride", allowDifferentOwnerOfOverride => new JValue(allowDifferentOwnerOfOverride) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expectsOverride", expectsOverride => new JValue(expectsOverride) }, - { "group", group => new JValue(group) }, - { "iid", iid => new JValue(iid) }, - { "isOptionDependent", isOptionDependent => new JValue(isOptionDependent) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "requestedBy", requestedBy => new JValue(requestedBy) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "stateDependence", stateDependence => new JValue(stateDependence) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + if (thing is not Parameter parameter) + { + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Parameter parameter) - { - var jsonObject = new JObject(); - jsonObject.Add("allowDifferentOwnerOfOverride", this.PropertySerializerMap["allowDifferentOwnerOfOverride"](parameter.AllowDifferentOwnerOfOverride)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expectsOverride", this.PropertySerializerMap["expectsOverride"](parameter.ExpectsOverride)); - jsonObject.Add("group", this.PropertySerializerMap["group"](parameter.Group)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameter.Iid)); - jsonObject.Add("isOptionDependent", this.PropertySerializerMap["isOptionDependent"](parameter.IsOptionDependent)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameter.Owner)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameter.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameter.ParameterType)); - jsonObject.Add("requestedBy", this.PropertySerializerMap["requestedBy"](parameter.RequestedBy)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameter.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameter.Scale)); - jsonObject.Add("stateDependence", this.PropertySerializerMap["stateDependence"](parameter.StateDependence)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameter.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameter.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.0.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.1.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.2.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameter.Actor.HasValue) + { + writer.WriteStringValue(parameter.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if(parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if(parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if(parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameter = thing as Parameter; - if (parameter == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Parameter."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "allowdifferentownerofoverride": + if(!AllowedVersionsPerProperty["allowDifferentOwnerOfOverride"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expectsoverride": + if(!AllowedVersionsPerProperty["expectsOverride"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("expectsOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(parameter); + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isoptiondependent": + if(!AllowedVersionsPerProperty["isOptionDependent"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isOptionDependent"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterSubscription"u8); + + if(value is IEnumerable objectListParameterSubscription) + { + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + } + + writer.WriteEndArray(); + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requestedby": + if(!AllowedVersionsPerProperty["requestedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requestedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "statedependence": + if(!AllowedVersionsPerProperty["stateDependence"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("stateDependence"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "allowDifferentOwnerOfOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expectsOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isOptionDependent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requestedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stateDependence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 410339886..6832b54a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscription = CDP4Common.DTO.ParameterSubscription; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,407 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscription parameterSubscription) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscription.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscription.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscription.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscription.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscription.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterSubscription.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscription.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscription.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterSubscription.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscription.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscription.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterSubscription = thing as ParameterSubscription; - if (parameterSubscription == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterSubscription."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterSubscription); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueSet"u8); + + if(value is IEnumerable objectListValueSet) + { + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscription"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index ec882c012..41371a9c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscriptionValueSet = CDP4Common.DTO.ParameterSubscriptionValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,392 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "subscribedValueSet", subscribedValueSet => new JValue(subscribedValueSet) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) + { + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscriptionValueSet parameterSubscriptionValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscriptionValueSet.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscriptionValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterSubscriptionValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscriptionValueSet.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscriptionValueSet.RevisionNumber)); - jsonObject.Add("subscribedValueSet", this.PropertySerializerMap["subscribedValueSet"](parameterSubscriptionValueSet.SubscribedValueSet)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscriptionValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterSubscriptionValueSet.ValueSwitch))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterSubscriptionValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterSubscriptionValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterSubscriptionValueSet = thing as ParameterSubscriptionValueSet; - if (parameterSubscriptionValueSet == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterSubscriptionValueSet."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(parameterSubscriptionValueSet); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "subscribedvalueset": + if(!AllowedVersionsPerProperty["subscribedValueSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("subscribedValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscriptionValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "subscribedValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 6f50b7afc..2c5253535 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterTypeComponent = CDP4Common.DTO.ParameterTypeComponent; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,442 @@ namespace CDP4JsonSerializer public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ParameterTypeComponent parameterTypeComponent) + { + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterTypeComponent parameterTypeComponent) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterTypeComponent.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterTypeComponent.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterTypeComponent.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterTypeComponent.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterTypeComponent.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameterTypeComponent.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterTypeComponent.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterTypeComponent.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterTypeComponent.Actor.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterTypeComponent = thing as ParameterTypeComponent; - if (parameterTypeComponent == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterTypeComponent."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(parameterTypeComponent); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterTypeComponent"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index a38d0e214..56326cec5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterValueSet = CDP4Common.DTO.ParameterValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,543 @@ namespace CDP4JsonSerializer public class ParameterValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "actualOption", actualOption => new JValue(actualOption) }, - { "actualState", actualState => new JValue(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + if (thing is not ParameterValueSet parameterValueSet) + { + throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterValueSet parameterValueSet) - { - var jsonObject = new JObject(); - jsonObject.Add("actualOption", this.PropertySerializerMap["actualOption"](parameterValueSet.ActualOption)); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](parameterValueSet.ActualState)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterValueSet.ModifiedOn)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterValueSet.ValueSwitch))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.0.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.1.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.2.0"); + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterValueSet.Actor.HasValue) + { + writer.WriteStringValue(parameterValueSet.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualOption"u8); + + if(parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if(parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterValueSet = thing as ParameterValueSet; - if (parameterValueSet == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterValueSet."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualoption": + if(!AllowedVersionsPerProperty["actualOption"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(parameterValueSet); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "formula": + if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index bca9f2207..a55f0d555 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterizedCategoryRule = CDP4Common.DTO.ParameterizedCategoryRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class ParameterizedCategoryRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JValue(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) + { + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParameterizedCategoryRule parameterizedCategoryRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](parameterizedCategoryRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](parameterizedCategoryRule.Category)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterizedCategoryRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](parameterizedCategoryRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterizedCategoryRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](parameterizedCategoryRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterizedCategoryRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterizedCategoryRule.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterizedCategoryRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterizedCategoryRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterizedCategoryRule.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parameterizedCategoryRule.Actor.HasValue) + { + writer.WriteStringValue(parameterizedCategoryRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parameterizedCategoryRule = thing as ParameterizedCategoryRule; - if (parameterizedCategoryRule == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterizedCategoryRule."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("category"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(parameterizedCategoryRule); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterizedCategoryRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 89fc9fc6b..225ac2c7e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParametricConstraint = CDP4Common.DTO.ParametricConstraint; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,443 @@ namespace CDP4JsonSerializer public class ParametricConstraintSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expression", expression => new JArray(expression) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topExpression", topExpression => new JValue(topExpression) }, - }; + if (thing is not ParametricConstraint parametricConstraint) + { + throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParametricConstraint parametricConstraint) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parametricConstraint.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parametricConstraint.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parametricConstraint.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expression", this.PropertySerializerMap["expression"](parametricConstraint.Expression.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parametricConstraint.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parametricConstraint.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parametricConstraint.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parametricConstraint.ThingPreference)); - jsonObject.Add("topExpression", this.PropertySerializerMap["topExpression"](parametricConstraint.TopExpression)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(parametricConstraint.Actor.HasValue) + { + writer.WriteStringValue(parametricConstraint.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if(parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var parametricConstraint = thing as ParametricConstraint; - if (parametricConstraint == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParametricConstraint."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(parametricConstraint); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "expression": + if(!AllowedVersionsPerProperty["expression"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("expression"u8); + + if(value is IEnumerable objectListExpression) + { + foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topexpression": + if(!AllowedVersionsPerProperty["topExpression"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("topExpression"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParametricConstraint"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topExpression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index 2365de57a..1f5e997d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantPermission = CDP4Common.DTO.ParticipantPermission; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParticipantPermission participantPermission) - { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.ParticipantAccessRightKind), participantPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantPermission.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(participantPermission.Actor.HasValue) + { + writer.WriteStringValue(participantPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var participantPermission = thing as ParticipantPermission; - if (participantPermission == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParticipantPermission."); - } + case "accessright": + if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((ParticipantAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(participantPermission); + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantPermission"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 5448bd2c0..6e9fdced3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantRole = CDP4Common.DTO.ParticipantRole; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class ParticipantRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "participantPermission", participantPermission => new JArray(participantPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ParticipantRole participantRole) + { + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ParticipantRole participantRole) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](participantRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](participantRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](participantRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](participantRole.Name)); - jsonObject.Add("participantPermission", this.PropertySerializerMap["participantPermission"](participantRole.ParticipantPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](participantRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantRole.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participantRole.Actor.HasValue) + { + writer.WriteStringValue(participantRole.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var participantRole = thing as ParticipantRole; - if (participantRole == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParticipantRole."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(participantRole); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "participantpermission": + if(!AllowedVersionsPerProperty["participantPermission"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participantPermission"u8); + + if(value is IEnumerable objectListParticipantPermission) + { + foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantRole"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index 55b6e0d5f..1f162cfc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Participant = CDP4Common.DTO.Participant; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,488 @@ namespace CDP4JsonSerializer public class ParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "person", person => new JValue(person) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "selectedDomain", selectedDomain => new JValue(selectedDomain) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Participant participant) + { + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Participant participant) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participant.ClassKind))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](participant.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participant.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](participant.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participant.ModifiedOn)); - jsonObject.Add("person", this.PropertySerializerMap["person"](participant.Person)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participant.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](participant.Role)); - jsonObject.Add("selectedDomain", this.PropertySerializerMap["selectedDomain"](participant.SelectedDomain)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participant.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(participant.Actor.HasValue) + { + writer.WriteStringValue(participant.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var participant = thing as Participant; - if (participant == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Participant."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(participant); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "person": + if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("person"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "selecteddomain": + if(!AllowedVersionsPerProperty["selectedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("selectedDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Participant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "selectedDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index b7523c936..a9ffb3fa6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonPermission = CDP4Common.DTO.PersonPermission; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,406 @@ namespace CDP4JsonSerializer public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PersonPermission personPermission) - { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.PersonAccessRightKind), personPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personPermission.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("actor"u8); + + if(personPermission.Actor.HasValue) + { + writer.WriteStringValue(personPermission.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var personPermission = thing as PersonPermission; - if (personPermission == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PersonPermission."); - } + case "accessright": + if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((PersonAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(personPermission); + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonPermission"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 913c625f5..780e0d508 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonRole = CDP4Common.DTO.PersonRole; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class PersonRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "personPermission", personPermission => new JArray(personPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not PersonRole personRole) + { + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PersonRole personRole) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](personRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](personRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](personRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](personRole.Name)); - jsonObject.Add("personPermission", this.PropertySerializerMap["personPermission"](personRole.PersonPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](personRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personRole.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(personRole.Actor.HasValue) + { + writer.WriteStringValue(personRole.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var personRole = thing as PersonRole; - if (personRole == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PersonRole."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(personRole); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "personpermission": + if(!AllowedVersionsPerProperty["personPermission"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("personPermission"u8); + + if(value is IEnumerable objectListPersonPermission) + { + foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonRole"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index badf6622e..5c6802131 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Person = CDP4Common.DTO.Person; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +51,994 @@ namespace CDP4JsonSerializer public class PersonSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultDomain", defaultDomain => new JValue(defaultDomain) }, - { "defaultEmailAddress", defaultEmailAddress => new JValue(defaultEmailAddress) }, - { "defaultTelephoneNumber", defaultTelephoneNumber => new JValue(defaultTelephoneNumber) }, - { "emailAddress", emailAddress => new JArray(emailAddress) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "givenName", givenName => new JValue(givenName) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "organizationalUnit", organizationalUnit => new JValue(organizationalUnit) }, - { "password", password => new JValue(password) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "shortName", shortName => new JValue(shortName) }, - { "surname", surname => new JValue(surname) }, - { "telephoneNumber", telephoneNumber => new JArray(telephoneNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "userPreference", userPreference => new JArray(userPreference) }, - }; + if (thing is not Person person) + { + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Person person) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), person.ClassKind))); - jsonObject.Add("defaultDomain", this.PropertySerializerMap["defaultDomain"](person.DefaultDomain)); - jsonObject.Add("defaultEmailAddress", this.PropertySerializerMap["defaultEmailAddress"](person.DefaultEmailAddress)); - jsonObject.Add("defaultTelephoneNumber", this.PropertySerializerMap["defaultTelephoneNumber"](person.DefaultTelephoneNumber)); - jsonObject.Add("emailAddress", this.PropertySerializerMap["emailAddress"](person.EmailAddress.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](person.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](person.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("givenName", this.PropertySerializerMap["givenName"](person.GivenName)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](person.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](person.IsActive)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](person.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](person.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](person.Organization)); - jsonObject.Add("organizationalUnit", this.PropertySerializerMap["organizationalUnit"](person.OrganizationalUnit)); - jsonObject.Add("password", this.PropertySerializerMap["password"](person.Password)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](person.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](person.Role)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](person.ShortName)); - jsonObject.Add("surname", this.PropertySerializerMap["surname"](person.Surname)); - jsonObject.Add("telephoneNumber", this.PropertySerializerMap["telephoneNumber"](person.TelephoneNumber.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](person.ThingPreference)); - jsonObject.Add("userPreference", this.PropertySerializerMap["userPreference"](person.UserPreference.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(person.Actor.HasValue) + { + writer.WriteStringValue(person.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if(person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if(person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if(person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var person = thing as Person; - if (person == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Person."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultdomain": + if(!AllowedVersionsPerProperty["defaultDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultemailaddress": + if(!AllowedVersionsPerProperty["defaultEmailAddress"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaulttelephonenumber": + if(!AllowedVersionsPerProperty["defaultTelephoneNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "emailaddress": + if(!AllowedVersionsPerProperty["emailAddress"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("emailAddress"u8); + + if(value is IEnumerable objectListEmailAddress) + { + foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(person); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "givenname": + if(!AllowedVersionsPerProperty["givenName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("givenName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalunit": + if(!AllowedVersionsPerProperty["organizationalUnit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("organizationalUnit"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "password": + if(!AllowedVersionsPerProperty["password"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("password"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "surname": + if(!AllowedVersionsPerProperty["surname"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("surname"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "telephonenumber": + if(!AllowedVersionsPerProperty["telephoneNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("telephoneNumber"u8); + + if(value is IEnumerable objectListTelephoneNumber) + { + foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "userpreference": + if(!AllowedVersionsPerProperty["userPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("userPreference"u8); + + if(value is IEnumerable objectListUserPreference) + { + foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultEmailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultTelephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "emailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "givenName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "password", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "surname", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "telephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "userPreference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index a6761fa54..4140edf0e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Point = CDP4Common.DTO.Point; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,391 @@ namespace CDP4JsonSerializer public class PointSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Point point) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), point.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](point.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](point.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](point.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](point.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](point.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](point.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](point.ThingPreference)); - jsonObject.Add("x", this.PropertySerializerMap["x"](point.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](point.Y)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(point.Actor.HasValue) + { + writer.WriteStringValue(point.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var point = thing as Point; - if (point == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Point."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(point); + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Point"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 485e31580..4c5bea084 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteStateList = CDP4Common.DTO.PossibleFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,744 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultState", defaultState => new JValue(defaultState) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "possibleState", possibleState => new JArray(((IEnumerable)possibleState).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteStateList possibleFiniteStateList) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteStateList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](possibleFiniteStateList.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteStateList.ClassKind))); - jsonObject.Add("defaultState", this.PropertySerializerMap["defaultState"](possibleFiniteStateList.DefaultState)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteStateList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteStateList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteStateList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteStateList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](possibleFiniteStateList.Owner)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](possibleFiniteStateList.PossibleState.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteStateList.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteStateList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteStateList.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(possibleFiniteStateList.Actor.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if(possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var possibleFiniteStateList = thing as PossibleFiniteStateList; - if (possibleFiniteStateList == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PossibleFiniteStateList."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultstate": + if(!AllowedVersionsPerProperty["defaultState"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(possibleFiniteStateList); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleState"u8); + + if(value is IEnumerable objectListPossibleState) + { + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteStateList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index 972d0f21f..0d47f7b5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteState = CDP4Common.DTO.PossibleFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,544 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not PossibleFiniteState possibleFiniteState) + { + throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteState possibleFiniteState) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteState.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteState.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteState.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteState.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteState.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteState.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteState.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteState.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteState.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteState.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(possibleFiniteState.Actor.HasValue) + { + writer.WriteStringValue(possibleFiniteState.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var possibleFiniteState = thing as PossibleFiniteState; - if (possibleFiniteState == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PossibleFiniteState."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(possibleFiniteState); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteState"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index 5c81c9c14..42104de74 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PrefixedUnit = CDP4Common.DTO.PrefixedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,571 @@ namespace CDP4JsonSerializer public class PrefixedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "prefix", prefix => new JValue(prefix) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not PrefixedUnit prefixedUnit) + { + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(PrefixedUnit prefixedUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](prefixedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), prefixedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](prefixedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](prefixedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](prefixedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](prefixedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](prefixedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](prefixedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](prefixedUnit.ModifiedOn)); - jsonObject.Add("prefix", this.PropertySerializerMap["prefix"](prefixedUnit.Prefix)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](prefixedUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](prefixedUnit.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](prefixedUnit.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(prefixedUnit.Actor.HasValue) + { + writer.WriteStringValue(prefixedUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var prefixedUnit = thing as PrefixedUnit; - if (prefixedUnit == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PrefixedUnit."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(prefixedUnit); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "prefix": + if(!AllowedVersionsPerProperty["prefix"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("prefix"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PrefixedUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "prefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index e30e92353..d1beffcf6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Publication = CDP4Common.DTO.Publication; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,462 @@ namespace CDP4JsonSerializer public class PublicationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "publishedParameter", publishedParameter => new JArray(publishedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Publication publication) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), publication.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](publication.CreatedOn)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](publication.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](publication.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](publication.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](publication.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](publication.ModifiedOn)); - jsonObject.Add("publishedParameter", this.PropertySerializerMap["publishedParameter"](publication.PublishedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](publication.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](publication.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(publication.Actor.HasValue) + { + writer.WriteStringValue(publication.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var publication = thing as Publication; - if (publication == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Publication."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(publication); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedparameter": + if(!AllowedVersionsPerProperty["publishedParameter"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("publishedParameter"u8); + + if(value is IEnumerable objectListPublishedParameter) + { + foreach(var publishedParameterItem in objectListPublishedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Publication"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 7cfaf72ac..966d9d818 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using QuantityKindFactor = CDP4Common.DTO.QuantityKindFactor; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "quantityKind", quantityKind => new JValue(quantityKind) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not QuantityKindFactor quantityKindFactor) + { + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(QuantityKindFactor quantityKindFactor) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), quantityKindFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](quantityKindFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](quantityKindFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](quantityKindFactor.ModifiedOn)); - jsonObject.Add("quantityKind", this.PropertySerializerMap["quantityKind"](quantityKindFactor.QuantityKind)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](quantityKindFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](quantityKindFactor.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(quantityKindFactor.Actor.HasValue) + { + writer.WriteStringValue(quantityKindFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var quantityKindFactor = thing as QuantityKindFactor; - if (quantityKindFactor == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a QuantityKindFactor."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(quantityKindFactor); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykind": + if(!AllowedVersionsPerProperty["quantityKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the QuantityKindFactor"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index d1cda6de1..b7edfc24c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RatioScale = CDP4Common.DTO.RatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +51,897 @@ namespace CDP4JsonSerializer public class RatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + if (thing is not RatioScale ratioScale) + { + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RatioScale ratioScale) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ratioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ratioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ratioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ratioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ratioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ratioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ratioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ratioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ratioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ratioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ratioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ratioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ratioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ratioScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ratioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ratioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ratioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ratioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ratioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ratioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ratioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ratioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ratioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ratioScale.Actor.HasValue) + { + writer.WriteStringValue(ratioScale.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var ratioScale = thing as RatioScale; - if (ratioScale == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RatioScale."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(ratioScale); + writer.WriteStartArray("mappingToReferenceScale"u8); + + if(value is IEnumerable objectListMappingToReferenceScale) + { + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "maximumpermissiblevalue": + if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueDefinition"u8); + + if(value is IEnumerable objectListValueDefinition) + { + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index 8e7cbe70a..c0b47518b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferenceSource = CDP4Common.DTO.ReferenceSource; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +51,959 @@ namespace CDP4JsonSerializer public class ReferenceSourceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "language", language => new JValue(language) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "publicationYear", publicationYear => new JValue(publicationYear) }, - { "publishedIn", publishedIn => new JValue(publishedIn) }, - { "publisher", publisher => new JValue(publisher) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "versionDate", versionDate => new JValue(versionDate != null ? ((DateTime)versionDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "versionIdentifier", versionIdentifier => new JValue(versionIdentifier) }, - }; + if (thing is not ReferenceSource referenceSource) + { + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReferenceSource referenceSource) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referenceSource.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](referenceSource.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](referenceSource.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referenceSource.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referenceSource.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referenceSource.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referenceSource.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referenceSource.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referenceSource.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referenceSource.IsDeprecated)); - jsonObject.Add("language", this.PropertySerializerMap["language"](referenceSource.Language)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referenceSource.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referenceSource.Name)); - jsonObject.Add("publicationYear", this.PropertySerializerMap["publicationYear"](referenceSource.PublicationYear)); - jsonObject.Add("publishedIn", this.PropertySerializerMap["publishedIn"](referenceSource.PublishedIn)); - jsonObject.Add("publisher", this.PropertySerializerMap["publisher"](referenceSource.Publisher)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referenceSource.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referenceSource.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referenceSource.ThingPreference)); - jsonObject.Add("versionDate", this.PropertySerializerMap["versionDate"](referenceSource.VersionDate)); - jsonObject.Add("versionIdentifier", this.PropertySerializerMap["versionIdentifier"](referenceSource.VersionIdentifier)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referenceSource.Actor.HasValue) + { + writer.WriteStringValue(referenceSource.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if(referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if(referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if(referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if(referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var referenceSource = thing as ReferenceSource; - if (referenceSource == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReferenceSource."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(referenceSource); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "language": + if(!AllowedVersionsPerProperty["language"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("language"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publicationyear": + if(!AllowedVersionsPerProperty["publicationYear"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publicationYear"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedin": + if(!AllowedVersionsPerProperty["publishedIn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publishedIn"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publisher": + if(!AllowedVersionsPerProperty["publisher"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("publisher"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versiondate": + if(!AllowedVersionsPerProperty["versionDate"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("versionDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versionidentifier": + if(!AllowedVersionsPerProperty["versionIdentifier"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("versionIdentifier"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferenceSource"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "language", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publicationYear", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedIn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publisher", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "versionDate", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "versionIdentifier", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index d0202ae49..36b9ef62a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferencerRule = CDP4Common.DTO.ReferencerRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +51,707 @@ namespace CDP4JsonSerializer public class ReferencerRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxReferenced", maxReferenced => new JValue(maxReferenced) }, - { "minReferenced", minReferenced => new JValue(minReferenced) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referencedCategory", referencedCategory => new JArray(referencedCategory) }, - { "referencingCategory", referencingCategory => new JValue(referencingCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReferencerRule referencerRule) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referencerRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referencerRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referencerRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referencerRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referencerRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referencerRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referencerRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referencerRule.IsDeprecated)); - jsonObject.Add("maxReferenced", this.PropertySerializerMap["maxReferenced"](referencerRule.MaxReferenced)); - jsonObject.Add("minReferenced", this.PropertySerializerMap["minReferenced"](referencerRule.MinReferenced)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referencerRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referencerRule.Name)); - jsonObject.Add("referencedCategory", this.PropertySerializerMap["referencedCategory"](referencerRule.ReferencedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencingCategory", this.PropertySerializerMap["referencingCategory"](referencerRule.ReferencingCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referencerRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referencerRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referencerRule.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(referencerRule.Actor.HasValue) + { + writer.WriteStringValue(referencerRule.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var referencerRule = thing as ReferencerRule; - if (referencerRule == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReferencerRule."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(referencerRule); + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxreferenced": + if(!AllowedVersionsPerProperty["maxReferenced"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("maxReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minreferenced": + if(!AllowedVersionsPerProperty["minReferenced"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("minReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedcategory": + if(!AllowedVersionsPerProperty["referencedCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referencedCategory"u8); + + if(value is IEnumerable objectListReferencedCategory) + { + foreach(var referencedCategoryItem in objectListReferencedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "referencingcategory": + if(!AllowedVersionsPerProperty["referencingCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferencerRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index 43ff2ed07..dd52a2064 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationalExpression = CDP4Common.DTO.RelationalExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +51,455 @@ namespace CDP4JsonSerializer public class RelationalExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "relationalOperator", relationalOperator => new JValue(relationalOperator.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + if (thing is not RelationalExpression relationalExpression) + { + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RelationalExpression relationalExpression) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationalExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationalExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationalExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationalExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationalExpression.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationalExpression.ParameterType)); - jsonObject.Add("relationalOperator", this.PropertySerializerMap["relationalOperator"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RelationalOperatorKind), relationalExpression.RelationalOperator))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationalExpression.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationalExpression.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationalExpression.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationalExpression.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationalExpression.Actor.HasValue) + { + writer.WriteStringValue(relationalExpression.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var relationalExpression = thing as RelationalExpression; - if (relationalExpression == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RelationalExpression."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(relationalExpression); + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationaloperator": + if(!AllowedVersionsPerProperty["relationalOperator"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("relationalOperator"u8); + + if(value != null) + { + writer.WriteStringValue(((RelationalOperatorKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationalExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationalOperator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 5c9a70191..751c35b7c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationshipParameterValue = CDP4Common.DTO.RelationshipParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,405 @@ namespace CDP4JsonSerializer public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + if (thing is not RelationshipParameterValue relationshipParameterValue) + { + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RelationshipParameterValue relationshipParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationshipParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationshipParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationshipParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationshipParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationshipParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationshipParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationshipParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationshipParameterValue.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(relationshipParameterValue.Actor.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var relationshipParameterValue = thing as RelationshipParameterValue; - if (relationshipParameterValue == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RelationshipParameterValue."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(relationshipParameterValue); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationshipParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 26a0ac910..8aabd337b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForDeviation = CDP4Common.DTO.RequestForDeviation; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +51,823 @@ namespace CDP4JsonSerializer public class RequestForDeviationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequestForDeviation requestForDeviation) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForDeviation.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForDeviation.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForDeviation.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForDeviation.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForDeviation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForDeviation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForDeviation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForDeviation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForDeviation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForDeviation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForDeviation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForDeviation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForDeviation.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForDeviation.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForDeviation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForDeviation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForDeviation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForDeviation.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForDeviation.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForDeviation.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForDeviation.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForDeviation.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForDeviation.Actor.HasValue) + { + writer.WriteStringValue(requestForDeviation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requestForDeviation = thing as RequestForDeviation; - if (requestForDeviation == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequestForDeviation."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(requestForDeviation); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForDeviation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index b958f63de..e083024a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForWaiver = CDP4Common.DTO.RequestForWaiver; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +51,823 @@ namespace CDP4JsonSerializer public class RequestForWaiverSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequestForWaiver requestForWaiver) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForWaiver.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForWaiver.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForWaiver.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForWaiver.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForWaiver.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForWaiver.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForWaiver.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForWaiver.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForWaiver.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForWaiver.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForWaiver.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForWaiver.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForWaiver.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForWaiver.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForWaiver.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForWaiver.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForWaiver.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForWaiver.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForWaiver.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForWaiver.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForWaiver.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForWaiver.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requestForWaiver.Actor.HasValue) + { + writer.WriteStringValue(requestForWaiver.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requestForWaiver = thing as RequestForWaiver; - if (requestForWaiver == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequestForWaiver."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(requestForWaiver); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForWaiver"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index d7be703a3..5edc2e7d7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Requirement = CDP4Common.DTO.Requirement; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,826 @@ namespace CDP4JsonSerializer public class RequirementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JValue(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "parametricConstraint", parametricConstraint => new JArray(((IEnumerable)parametricConstraint).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Requirement requirement) + { + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Requirement requirement) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirement.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirement.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirement.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirement.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirement.Group)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirement.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirement.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirement.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirement.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirement.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirement.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirement.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parametricConstraint", this.PropertySerializerMap["parametricConstraint"](requirement.ParametricConstraint.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirement.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirement.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirement.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirement.Actor.HasValue) + { + writer.WriteStringValue(requirement.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if(requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requirement = thing as Requirement; - if (requirement == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Requirement."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(requirement); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "parametricconstraint": + if(!AllowedVersionsPerProperty["parametricConstraint"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parametricConstraint"u8); + + if(value is IEnumerable objectListParametricConstraint) + { + foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Requirement"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parametricConstraint", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index f231c7807..cd791bb98 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsContainerParameterValue = CDP4Common.DTO.RequirementsContainerParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,405 @@ namespace CDP4JsonSerializer public class RequirementsContainerParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) + { + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsContainerParameterValue requirementsContainerParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsContainerParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsContainerParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsContainerParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](requirementsContainerParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsContainerParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](requirementsContainerParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsContainerParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](requirementsContainerParameterValue.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsContainerParameterValue.Actor.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requirementsContainerParameterValue = thing as RequirementsContainerParameterValue; - if (requirementsContainerParameterValue == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsContainerParameterValue."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(requirementsContainerParameterValue); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsContainerParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 5f5755eb2..31cc56d6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsGroup = CDP4Common.DTO.RequirementsGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,718 @@ namespace CDP4JsonSerializer public class RequirementsGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsGroup requirementsGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsGroup.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsGroup.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsGroup.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsGroup.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsGroup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsGroup.Actor.HasValue) + { + writer.WriteStringValue(requirementsGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requirementsGroup = thing as RequirementsGroup; - if (requirementsGroup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsGroup."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(requirementsGroup); + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("group"u8); + + if(value is IEnumerable objectListGroup) + { + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 68aa0f9a3..a237a7fb8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsSpecification = CDP4Common.DTO.RequirementsSpecification; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,800 @@ namespace CDP4JsonSerializer public class RequirementsSpecificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RequirementsSpecification requirementsSpecification) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsSpecification.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsSpecification.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsSpecification.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsSpecification.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsSpecification.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsSpecification.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsSpecification.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirementsSpecification.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsSpecification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsSpecification.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsSpecification.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsSpecification.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](requirementsSpecification.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsSpecification.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsSpecification.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsSpecification.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(requirementsSpecification.Actor.HasValue) + { + writer.WriteStringValue(requirementsSpecification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var requirementsSpecification = thing as RequirementsSpecification; - if (requirementsSpecification == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsSpecification."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(requirementsSpecification); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "group": + if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("group"u8); + + if(value is IEnumerable objectListGroup) + { + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterValue"u8); + + if(value is IEnumerable objectListParameterValue) + { + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + } + + writer.WriteEndArray(); + break; + case "requirement": + if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirement"u8); + + if(value is IEnumerable objectListRequirement) + { + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsSpecification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index b82dec136..bd78f1344 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReviewItemDiscrepancy = CDP4Common.DTO.ReviewItemDiscrepancy; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +51,869 @@ namespace CDP4JsonSerializer public class ReviewItemDiscrepancySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "solution", solution => new JArray(solution) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) + { + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ReviewItemDiscrepancy reviewItemDiscrepancy) - { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](reviewItemDiscrepancy.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](reviewItemDiscrepancy.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), reviewItemDiscrepancy.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), reviewItemDiscrepancy.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](reviewItemDiscrepancy.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](reviewItemDiscrepancy.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](reviewItemDiscrepancy.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](reviewItemDiscrepancy.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](reviewItemDiscrepancy.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](reviewItemDiscrepancy.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](reviewItemDiscrepancy.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](reviewItemDiscrepancy.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](reviewItemDiscrepancy.ShortName)); - jsonObject.Add("solution", this.PropertySerializerMap["solution"](reviewItemDiscrepancy.Solution)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), reviewItemDiscrepancy.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](reviewItemDiscrepancy.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](reviewItemDiscrepancy.Title)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(reviewItemDiscrepancy.Actor.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var reviewItemDiscrepancy = thing as ReviewItemDiscrepancy; - if (reviewItemDiscrepancy == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReviewItemDiscrepancy."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("approvedBy"u8); + + if(value is IEnumerable objectListApprovedBy) + { + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classification": + if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(reviewItemDiscrepancy); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "solution": + if(!AllowedVersionsPerProperty["solution"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("solution"u8); + + if(value is IEnumerable objectListSolution) + { + foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + } + + writer.WriteEndArray(); + break; + case "sourceannotation": + if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("sourceAnnotation"u8); + + if(value is IEnumerable objectListSourceAnnotation) + { + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + } + + writer.WriteEndArray(); + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReviewItemDiscrepancy"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "solution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index 5b84f0ec5..5cf08a6b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleVerificationList = CDP4Common.DTO.RuleVerificationList; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,626 @@ namespace CDP4JsonSerializer public class RuleVerificationListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerification", ruleVerification => new JArray(((IEnumerable)ruleVerification).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not RuleVerificationList ruleVerificationList) + { + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RuleVerificationList ruleVerificationList) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ruleVerificationList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleVerificationList.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ruleVerificationList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ruleVerificationList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleVerificationList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleVerificationList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ruleVerificationList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](ruleVerificationList.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleVerificationList.RevisionNumber)); - jsonObject.Add("ruleVerification", this.PropertySerializerMap["ruleVerification"](ruleVerificationList.RuleVerification.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ruleVerificationList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleVerificationList.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleVerificationList.Actor.HasValue) + { + writer.WriteStringValue(ruleVerificationList.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var ruleVerificationList = thing as RuleVerificationList; - if (ruleVerificationList == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RuleVerificationList."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(ruleVerificationList); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverification": + if(!AllowedVersionsPerProperty["ruleVerification"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("ruleVerification"u8); + + if(value is IEnumerable objectListRuleVerification) + { + foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleVerificationList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index cd42eb719..a37d9bcd0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleViolation = CDP4Common.DTO.RuleViolation; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,407 @@ namespace CDP4JsonSerializer public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violatingThing", violatingThing => new JArray(violatingThing) }, - }; + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(RuleViolation ruleViolation) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleViolation.ClassKind))); - jsonObject.Add("description", this.PropertySerializerMap["description"](ruleViolation.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleViolation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleViolation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleViolation.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleViolation.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleViolation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleViolation.ThingPreference)); - jsonObject.Add("violatingThing", this.PropertySerializerMap["violatingThing"](ruleViolation.ViolatingThing.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(ruleViolation.Actor.HasValue) + { + writer.WriteStringValue(ruleViolation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var ruleViolation = thing as RuleViolation; - if (ruleViolation == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RuleViolation."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(ruleViolation); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violatingthing": + if(!AllowedVersionsPerProperty["violatingThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violatingThing"u8); + + if(value is IEnumerable objectListViolatingThing) + { + foreach(var violatingThingItem in objectListViolatingThing) + { + writer.WriteStringValue((Guid)violatingThingItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleViolation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violatingThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index 70fc7237e..80cb84791 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SampledFunctionParameterType = CDP4Common.DTO.SampledFunctionParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +51,653 @@ namespace CDP4JsonSerializer public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "degreeOfInterpolation", degreeOfInterpolation => new JValue(degreeOfInterpolation) }, - { "dependentParameterType", dependentParameterType => new JArray(((IEnumerable)dependentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "independentParameterType", independentParameterType => new JArray(((IEnumerable)independentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "interpolationPeriod", interpolationPeriod => new JValue(((ValueArray)interpolationPeriod).ToJsonString()) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SampledFunctionParameterType sampledFunctionParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](sampledFunctionParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](sampledFunctionParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sampledFunctionParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](sampledFunctionParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("degreeOfInterpolation", this.PropertySerializerMap["degreeOfInterpolation"](sampledFunctionParameterType.DegreeOfInterpolation)); - jsonObject.Add("dependentParameterType", this.PropertySerializerMap["dependentParameterType"](sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sampledFunctionParameterType.Iid)); - jsonObject.Add("independentParameterType", this.PropertySerializerMap["independentParameterType"](sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("interpolationPeriod", this.PropertySerializerMap["interpolationPeriod"](sampledFunctionParameterType.InterpolationPeriod)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](sampledFunctionParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sampledFunctionParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sampledFunctionParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sampledFunctionParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](sampledFunctionParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](sampledFunctionParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sampledFunctionParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.2.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sampledFunctionParameterType.Actor.HasValue) + { + writer.WriteStringValue(sampledFunctionParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var sampledFunctionParameterType = thing as SampledFunctionParameterType; - if (sampledFunctionParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SampledFunctionParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "degreeofinterpolation": + if(!AllowedVersionsPerProperty["degreeOfInterpolation"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "dependentparametertype": + if(!AllowedVersionsPerProperty["dependentParameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("dependentParameterType"u8); + + if(value is IEnumerable objectListDependentParameterType) + { + foreach(var dependentParameterTypeItem in objectListDependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(sampledFunctionParameterType); + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "independentparametertype": + if(!AllowedVersionsPerProperty["independentParameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("independentParameterType"u8); + + if(value is IEnumerable objectListIndependentParameterType) + { + foreach(var independentParameterTypeItem in objectListIndependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "interpolationperiod": + if(!AllowedVersionsPerProperty["interpolationPeriod"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("interpolationPeriod"u8, ((ValueArray)value).ToJsonString()); + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SampledFunctionParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.2.0", "1.3.0" }}, + { "category", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.2.0", "1.3.0" }}, + { "degreeOfInterpolation", new []{ "1.2.0", "1.3.0" }}, + { "dependentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "independentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "interpolationPeriod", new []{ "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index 28ac8fcba..5852aa471 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleReferenceQuantityValue = CDP4Common.DTO.ScaleReferenceQuantityValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) + { + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ScaleReferenceQuantityValue scaleReferenceQuantityValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleReferenceQuantityValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleReferenceQuantityValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleReferenceQuantityValue.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleReferenceQuantityValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](scaleReferenceQuantityValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleReferenceQuantityValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleReferenceQuantityValue.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleReferenceQuantityValue.Actor.HasValue) + { + writer.WriteStringValue(scaleReferenceQuantityValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var scaleReferenceQuantityValue = thing as ScaleReferenceQuantityValue; - if (scaleReferenceQuantityValue == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ScaleReferenceQuantityValue."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(scaleReferenceQuantityValue); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleReferenceQuantityValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index ee7e18806..b1adb3c9b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleValueDefinition = CDP4Common.DTO.ScaleValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,571 @@ namespace CDP4JsonSerializer public class ScaleValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + if (thing is not ScaleValueDefinition scaleValueDefinition) + { + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ScaleValueDefinition scaleValueDefinition) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](scaleValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](scaleValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](scaleValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](scaleValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](scaleValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleValueDefinition.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleValueDefinition.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(scaleValueDefinition.Actor.HasValue) + { + writer.WriteStringValue(scaleValueDefinition.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var scaleValueDefinition = thing as ScaleValueDefinition; - if (scaleValueDefinition == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ScaleValueDefinition."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(scaleValueDefinition); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleValueDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 6898f9908..3d4aa0bf9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Section = CDP4Common.DTO.Section; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,508 @@ namespace CDP4JsonSerializer public class SectionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "page", page => new JArray(((IEnumerable)page).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Section section) + { + throw new ArgumentException("The thing shall be a Section", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Section section) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](section.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), section.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](section.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](section.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](section.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](section.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](section.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](section.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](section.Owner)); - jsonObject.Add("page", this.PropertySerializerMap["page"](section.Page.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](section.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](section.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](section.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(section.Actor.HasValue) + { + writer.WriteStringValue(section.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var section = thing as Section; - if (section == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Section."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(section); + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "page": + if(!AllowedVersionsPerProperty["page"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("page"u8); + + if(value is IEnumerable objectListPage) + { + foreach(var pageItem in objectListPage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Section"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "page", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs index 648e2387f..e638d2d62 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -31,14 +30,13 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - + using System.Text.Json; + using CDP4Common; using CDP4Common.DTO; - + using CDP4JsonSerializer.Helper; - using Newtonsoft.Json.Linq; - /// /// A static class that provides method to serialize a or a /// @@ -47,7 +45,7 @@ public static class SerializerProvider /// /// The map containing the Serializers /// - private static readonly Dictionary SerializerMap = new Dictionary + private static readonly Dictionary SerializerMap = new() { { "ActionItem", new ActionItemSerializer() }, { "ActualFiniteState", new ActualFiniteStateSerializer() }, @@ -198,42 +196,43 @@ public static class SerializerProvider }; /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this Thing thing) + /// The + /// The that has been requested for the serialization + public static void SerializeThing(this Thing thing, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out serializer)) + if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out var serializer)) { throw new NotSupportedException($"The {thing.ClassKind} class is not registered"); } - - return serializer.Serialize(thing); + + serializer.Serialize(thing, writer, requestedVersion); } - + /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this ClasslessDTO classlessDto) + /// The + /// The that has been requested for the serialization + public static void SerializeClasslessDto(this ClasslessDTO classlessDto, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out serializer)) + if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out var serializer)) { throw new NotSupportedException($"The {classlessDto["ClassKind"]} class is not registered"); } - var jsonObject = new JObject(); + writer.WriteStartObject(); + foreach (var keyValue in classlessDto) { var key = Utils.LowercaseFirstLetter(keyValue.Key); - jsonObject.Add(key, serializer.PropertySerializerMap[key](keyValue.Value)); + serializer.SerializeProperty(key, keyValue.Value, writer, requestedVersion); } - return jsonObject; + writer.WriteEndObject(); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index beb6b015a..2ced7f763 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SharedStyle = CDP4Common.DTO.SharedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +51,984 @@ namespace CDP4JsonSerializer public class SharedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + if (thing is not SharedStyle sharedStyle) + { + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SharedStyle sharedStyle) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sharedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sharedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sharedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](sharedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](sharedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](sharedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](sharedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](sharedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](sharedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](sharedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](sharedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](sharedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sharedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sharedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sharedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sharedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](sharedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](sharedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](sharedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sharedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](sharedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(sharedStyle.Actor.HasValue) + { + writer.WriteStringValue(sharedStyle.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if(sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if(sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if(sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if(sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if(sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if(sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if(sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if(sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if(sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var sharedStyle = thing as SharedStyle; - if (sharedStyle == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SharedStyle."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "fillcolor": + if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(sharedStyle); + break; + case "fontbold": + if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontitalic": + if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("usedColor"u8); + + if(value is IEnumerable objectListUsedColor) + { + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 90423aaf9..4abe7173d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleParameterValue = CDP4Common.DTO.SimpleParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,428 @@ namespace CDP4JsonSerializer public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + if (thing is not SimpleParameterValue simpleParameterValue) + { + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleParameterValue simpleParameterValue) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](simpleParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](simpleParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](simpleParameterValue.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleParameterValue.Actor.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if(simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var simpleParameterValue = thing as SimpleParameterValue; - if (simpleParameterValue == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleParameterValue."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(simpleParameterValue); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index f054c44dc..0381206b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleQuantityKind = CDP4Common.DTO.SimpleQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,762 @@ namespace CDP4JsonSerializer public class SimpleQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SimpleQuantityKind simpleQuantityKind) + { + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleQuantityKind simpleQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](simpleQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](simpleQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](simpleQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](simpleQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](simpleQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleQuantityKind.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(simpleQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var simpleQuantityKind = thing as SimpleQuantityKind; - if (simpleQuantityKind == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleQuantityKind."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(simpleQuantityKind); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 1dc7043c0..95afddc3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleUnit = CDP4Common.DTO.SimpleUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,571 @@ namespace CDP4JsonSerializer public class SimpleUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SimpleUnit simpleUnit) + { + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SimpleUnit simpleUnit) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleUnit.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(simpleUnit.Actor.HasValue) + { + writer.WriteStringValue(simpleUnit.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var simpleUnit = thing as SimpleUnit; - if (simpleUnit == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleUnit."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(simpleUnit); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 404eb26b5..727c19091 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataAnnotation = CDP4Common.DTO.SiteDirectoryDataAnnotation; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,533 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataAnnotation.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataAnnotation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataAnnotation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataAnnotation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataAnnotation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataAnnotation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataAnnotation.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](siteDirectoryDataAnnotation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataAnnotation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataAnnotation.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataAnnotation.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataAnnotation.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteDirectoryDataAnnotation = thing as SiteDirectoryDataAnnotation; - if (siteDirectoryDataAnnotation == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataAnnotation."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("discussion"u8); + + if(value is IEnumerable objectListDiscussion) + { + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(siteDirectoryDataAnnotation); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("relatedThing"u8); + + if(value is IEnumerable objectListRelatedThing) + { + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataAnnotation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index b5288bb8d..227f64e26 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataDiscussionItem = CDP4Common.DTO.SiteDirectoryDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,468 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](siteDirectoryDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataDiscussionItem.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryDataDiscussionItem.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteDirectoryDataDiscussionItem = thing as SiteDirectoryDataDiscussionItem; - if (siteDirectoryDataDiscussionItem == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataDiscussionItem."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(siteDirectoryDataDiscussionItem); + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataDiscussionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index ceb881080..64dd01191 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectory = CDP4Common.DTO.SiteDirectory; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +51,1155 @@ namespace CDP4JsonSerializer public class SiteDirectorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "annotation", annotation => new JArray(annotation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "defaultParticipantRole", defaultParticipantRole => new JValue(defaultParticipantRole) }, - { "defaultPersonRole", defaultPersonRole => new JValue(defaultPersonRole) }, - { "domain", domain => new JArray(domain) }, - { "domainGroup", domainGroup => new JArray(domainGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "model", model => new JArray(model) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "naturalLanguage", naturalLanguage => new JArray(naturalLanguage) }, - { "organization", organization => new JArray(organization) }, - { "participantRole", participantRole => new JArray(participantRole) }, - { "person", person => new JArray(person) }, - { "personRole", personRole => new JArray(personRole) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "siteReferenceDataLibrary", siteReferenceDataLibrary => new JArray(siteReferenceDataLibrary) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SiteDirectory siteDirectory) + { + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectory siteDirectory) - { - var jsonObject = new JObject(); - jsonObject.Add("annotation", this.PropertySerializerMap["annotation"](siteDirectory.Annotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectory.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectory.CreatedOn)); - jsonObject.Add("defaultParticipantRole", this.PropertySerializerMap["defaultParticipantRole"](siteDirectory.DefaultParticipantRole)); - jsonObject.Add("defaultPersonRole", this.PropertySerializerMap["defaultPersonRole"](siteDirectory.DefaultPersonRole)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](siteDirectory.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainGroup", this.PropertySerializerMap["domainGroup"](siteDirectory.DomainGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectory.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectory.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectory.Iid)); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](siteDirectory.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](siteDirectory.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("model", this.PropertySerializerMap["model"](siteDirectory.Model.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectory.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteDirectory.Name)); - jsonObject.Add("naturalLanguage", this.PropertySerializerMap["naturalLanguage"](siteDirectory.NaturalLanguage.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](siteDirectory.Organization.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participantRole", this.PropertySerializerMap["participantRole"](siteDirectory.ParticipantRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("person", this.PropertySerializerMap["person"](siteDirectory.Person.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("personRole", this.PropertySerializerMap["personRole"](siteDirectory.PersonRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectory.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteDirectory.ShortName)); - jsonObject.Add("siteReferenceDataLibrary", this.PropertySerializerMap["siteReferenceDataLibrary"](siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectory.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectory.Actor.HasValue) + { + writer.WriteStringValue(siteDirectory.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteDirectory = thing as SiteDirectory; - if (siteDirectory == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectory."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "annotation": + if(!AllowedVersionsPerProperty["annotation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("annotation"u8); + + if(value is IEnumerable objectListAnnotation) + { + foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultparticipantrole": + if(!AllowedVersionsPerProperty["defaultParticipantRole"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(siteDirectory); + writer.WritePropertyName("defaultParticipantRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultpersonrole": + if(!AllowedVersionsPerProperty["defaultPersonRole"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domain"u8); + + if(value is IEnumerable objectListDomain) + { + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + } + + writer.WriteEndArray(); + break; + case "domaingroup": + if(!AllowedVersionsPerProperty["domainGroup"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("domainGroup"u8); + + if(value is IEnumerable objectListDomainGroup) + { + foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lastmodifiedon": + if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntry"u8); + + if(value is IEnumerable objectListLogEntry) + { + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + } + + writer.WriteEndArray(); + break; + case "model": + if(!AllowedVersionsPerProperty["model"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("model"u8); + + if(value is IEnumerable objectListModel) + { + foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "naturallanguage": + if(!AllowedVersionsPerProperty["naturalLanguage"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("naturalLanguage"u8); + + if(value is IEnumerable objectListNaturalLanguage) + { + foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + } + + writer.WriteEndArray(); + break; + case "organization": + if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("organization"u8); + + if(value is IEnumerable objectListOrganization) + { + foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + } + + writer.WriteEndArray(); + break; + case "participantrole": + if(!AllowedVersionsPerProperty["participantRole"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("participantRole"u8); + + if(value is IEnumerable objectListParticipantRole) + { + foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + } + + writer.WriteEndArray(); + break; + case "person": + if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("person"u8); + + if(value is IEnumerable objectListPerson) + { + foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + } + + writer.WriteEndArray(); + break; + case "personrole": + if(!AllowedVersionsPerProperty["personRole"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("personRole"u8); + + if(value is IEnumerable objectListPersonRole) + { + foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sitereferencedatalibrary": + if(!AllowedVersionsPerProperty["siteReferenceDataLibrary"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + if(value is IEnumerable objectListSiteReferenceDataLibrary) + { + foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectory"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "annotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultParticipantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultPersonRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domainGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "model", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "naturalLanguage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "siteReferenceDataLibrary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 09e8f6335..4600c357d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryThingReference = CDP4Common.DTO.SiteDirectoryThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,366 @@ namespace CDP4JsonSerializer public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) + { + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryThingReference siteDirectoryThingReference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](siteDirectoryThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](siteDirectoryThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryThingReference.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteDirectoryThingReference.Actor.HasValue) + { + writer.WriteStringValue(siteDirectoryThingReference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteDirectoryThingReference = thing as SiteDirectoryThingReference; - if (siteDirectoryThingReference == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryThingReference."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(siteDirectoryThingReference); + break; + case "referencedrevisionnumber": + if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryThingReference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 72020995e..407871d73 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteLogEntry = CDP4Common.DTO.SiteLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +51,698 @@ namespace CDP4JsonSerializer public class SiteLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteLogEntry siteLogEntry) - { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](siteLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](siteLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](siteLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), siteLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteLogEntry.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteLogEntry.Actor.HasValue) + { + writer.WriteStringValue(siteLogEntry.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if(siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteLogEntry = thing as SiteLogEntry; - if (siteLogEntry == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteLogEntry."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affecteddomainiid": + if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedDomainIid"u8); + + if(value is IEnumerable objectListAffectedDomainIid) + { + foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + } + + writer.WriteEndArray(); + break; + case "affecteditemiid": + if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("affectedItemIid"u8); + + if(value is IEnumerable objectListAffectedItemIid) + { + foreach(var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + } + + writer.WriteEndArray(); + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(siteLogEntry); + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("logEntryChangelogItem"u8); + + if(value is IEnumerable objectListLogEntryChangelogItem) + { + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + } + + writer.WriteEndArray(); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteLogEntry"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index e8b0db415..d4efc9722 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteReferenceDataLibrary = CDP4Common.DTO.SiteReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -45,104 +51,1294 @@ namespace CDP4JsonSerializer public class SiteReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SiteReferenceDataLibrary siteReferenceDataLibrary) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](siteReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](siteReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](siteReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](siteReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteReferenceDataLibrary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](siteReferenceDataLibrary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](siteReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](siteReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](siteReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](siteReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(siteReferenceDataLibrary.Actor.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if(siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var siteReferenceDataLibrary = thing as SiteReferenceDataLibrary; - if (siteReferenceDataLibrary == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteReferenceDataLibrary."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "basequantitykind": + if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(siteReferenceDataLibrary); + writer.WriteStartArray("baseQuantityKind"u8); + + if(value is IEnumerable objectListBaseQuantityKind) + { + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + } + + writer.WriteEndArray(); + break; + case "baseunit": + if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("baseUnit"u8); + + if(value is IEnumerable objectListBaseUnit) + { + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("constant"u8); + + if(value is IEnumerable objectListConstant) + { + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + } + + writer.WriteEndArray(); + break; + case "definedcategory": + if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definedCategory"u8); + + if(value is IEnumerable objectListDefinedCategory) + { + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + } + + writer.WriteEndArray(); + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "filetype": + if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("fileType"u8); + + if(value is IEnumerable objectListFileType) + { + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "glossary": + if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("glossary"u8); + + if(value is IEnumerable objectListGlossary) + { + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("parameterType"u8); + + if(value is IEnumerable objectListParameterType) + { + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + } + + writer.WriteEndArray(); + break; + case "referencesource": + if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("referenceSource"u8); + + if(value is IEnumerable objectListReferenceSource) + { + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + } + + writer.WriteEndArray(); + break; + case "requiredrdl": + if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("rule"u8); + + if(value is IEnumerable objectListRule) + { + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + } + + writer.WriteEndArray(); + break; + case "scale": + if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("scale"u8); + + if(value is IEnumerable objectListScale) + { + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unit"u8); + + if(value is IEnumerable objectListUnit) + { + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + } + + writer.WriteEndArray(); + break; + case "unitprefix": + if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("unitPrefix"u8); + + if(value is IEnumerable objectListUnitPrefix) + { + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index b4d922433..4bfe39b12 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Solution = CDP4Common.DTO.Solution; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +51,441 @@ namespace CDP4JsonSerializer public class SolutionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Solution solution) + { + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Solution solution) - { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](solution.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), solution.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](solution.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](solution.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](solution.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](solution.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](solution.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](solution.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](solution.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](solution.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](solution.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](solution.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(solution.Actor.HasValue) + { + writer.WriteStringValue(solution.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var solution = thing as Solution; - if (solution == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Solution."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "author": + if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(solution); + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Solution"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index ef87f7738..eac937655 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SpecializedQuantityKind = CDP4Common.DTO.SpecializedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +51,789 @@ namespace CDP4JsonSerializer public class SpecializedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "general", general => new JValue(general) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(SpecializedQuantityKind specializedQuantityKind) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](specializedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](specializedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), specializedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](specializedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](specializedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("general", this.PropertySerializerMap["general"](specializedQuantityKind.General)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](specializedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](specializedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](specializedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](specializedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](specializedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](specializedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](specializedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](specializedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](specializedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](specializedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](specializedQuantityKind.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(specializedQuantityKind.Actor.HasValue) + { + writer.WriteStringValue(specializedQuantityKind.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var specializedQuantityKind = thing as SpecializedQuantityKind; - if (specializedQuantityKind == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SpecializedQuantityKind."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "general": + if(!AllowedVersionsPerProperty["general"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(specializedQuantityKind); + writer.WritePropertyName("general"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("possibleScale"u8); + + if(value is IEnumerable objectListPossibleScale) + { + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + } + + writer.WriteEndArray(); + break; + case "quantitydimensionsymbol": + if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SpecializedQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "general", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 8103951a9..140d52943 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMap = CDP4Common.DTO.StakeHolderValueMap; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +51,780 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goal", goal => new JArray(goal) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "settings", settings => new JArray(settings) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + if (thing is not StakeHolderValueMap stakeHolderValueMap) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMap stakeHolderValueMap) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeHolderValueMap.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeHolderValueMap.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMap.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeHolderValueMap.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](stakeHolderValueMap.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeHolderValueMap.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeHolderValueMap.Name)); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](stakeHolderValueMap.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMap.RevisionNumber)); - jsonObject.Add("settings", this.PropertySerializerMap["settings"](stakeHolderValueMap.Settings)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeHolderValueMap.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMap.ThingPreference)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeHolderValueMap.Actor.HasValue) + { + writer.WriteStringValue(stakeHolderValueMap.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var stakeHolderValueMap = thing as StakeHolderValueMap; - if (stakeHolderValueMap == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMap."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(stakeHolderValueMap); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goal": + if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("goal"u8); + + if(value is IEnumerable objectListGoal) + { + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requirement": + if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("requirement"u8); + + if(value is IEnumerable objectListRequirement) + { + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + } + + writer.WriteEndArray(); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "settings": + if(!AllowedVersionsPerProperty["settings"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("settings"u8); + + if(value is IEnumerable objectListSettings) + { + foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + } + + writer.WriteEndArray(); + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("valueGroup"u8); + + if(value is IEnumerable objectListValueGroup) + { + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "settings", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 9d424947f..9a0ecc249 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMapSettings = CDP4Common.DTO.StakeHolderValueMapSettings; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +51,472 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSettingsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goalToValueGroupRelationship", goalToValueGroupRelationship => new JValue(goalToValueGroupRelationship) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "stakeholderValueToRequirementRelationship", stakeholderValueToRequirementRelationship => new JValue(stakeholderValueToRequirementRelationship) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroupToStakeholderValueRelationship", valueGroupToStakeholderValueRelationship => new JValue(valueGroupToStakeholderValueRelationship) }, - }; + if (thing is not StakeHolderValueMapSettings stakeHolderValueMapSettings) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMapSettings stakeHolderValueMapSettings) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMapSettings.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goalToValueGroupRelationship", this.PropertySerializerMap["goalToValueGroupRelationship"](stakeHolderValueMapSettings.GoalToValueGroupRelationship)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMapSettings.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMapSettings.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMapSettings.RevisionNumber)); - jsonObject.Add("stakeholderValueToRequirementRelationship", this.PropertySerializerMap["stakeholderValueToRequirementRelationship"](stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMapSettings.ThingPreference)); - jsonObject.Add("valueGroupToStakeholderValueRelationship", this.PropertySerializerMap["valueGroupToStakeholderValueRelationship"](stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeHolderValueMapSettings.Actor.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var stakeHolderValueMapSettings = thing as StakeHolderValueMapSettings; - if (stakeHolderValueMapSettings == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMapSettings."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "goaltovaluegrouprelationship": + if(!AllowedVersionsPerProperty["goalToValueGroupRelationship"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(stakeHolderValueMapSettings); + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervaluetorequirementrelationship": + if(!AllowedVersionsPerProperty["stakeholderValueToRequirementRelationship"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegrouptostakeholdervaluerelationship": + if(!AllowedVersionsPerProperty["valueGroupToStakeholderValueRelationship"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMapSettings"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goalToValueGroupRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueToRequirementRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroupToStakeholderValueRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 7d46ac59c..4e34a4882 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Stakeholder = CDP4Common.DTO.Stakeholder; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,596 @@ namespace CDP4JsonSerializer public class StakeholderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Stakeholder stakeholder) + { + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Stakeholder stakeholder) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholder.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholder.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholder.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholder.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholder.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholder.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholder.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholder.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeholder.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholder.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholder.Actor.HasValue) + { + writer.WriteStringValue(stakeholder.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var stakeholder = thing as Stakeholder; - if (stakeholder == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Stakeholder."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(stakeholder); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("stakeholderValue"u8); + + if(value is IEnumerable objectListStakeholderValue) + { + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + } + + writer.WriteEndArray(); + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Stakeholder"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 6d2a41808..5279e8a3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeholderValue = CDP4Common.DTO.StakeholderValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,550 @@ namespace CDP4JsonSerializer public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(StakeholderValue stakeholderValue) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholderValue.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholderValue.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholderValue.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholderValue.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholderValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholderValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholderValue.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholderValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholderValue.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholderValue.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholderValue.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholderValue.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholderValue.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(stakeholderValue.Actor.HasValue) + { + writer.WriteStringValue(stakeholderValue.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var stakeholderValue = thing as StakeholderValue; - if (stakeholderValue == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeholderValue."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(stakeholderValue); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeholderValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index e4ddfde5e..edd1133a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TelephoneNumber = CDP4Common.DTO.TelephoneNumber; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,407 @@ namespace CDP4JsonSerializer public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JArray(vcardType) }, - }; + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TelephoneNumber telephoneNumber) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), telephoneNumber.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](telephoneNumber.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](telephoneNumber.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](telephoneNumber.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](telephoneNumber.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](telephoneNumber.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](telephoneNumber.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](telephoneNumber.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](telephoneNumber.VcardType.Select(e => Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardTelephoneNumberKind), e)))); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(telephoneNumber.Actor.HasValue) + { + writer.WriteStringValue(telephoneNumber.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var telephoneNumber = thing as TelephoneNumber; - if (telephoneNumber == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TelephoneNumber."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(telephoneNumber); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("vcardType"u8); + + if(value is IEnumerable objectListVcardType) + { + foreach(var vcardTypeItem in objectListVcardType) + { + writer.WriteStringValue(((VcardTelephoneNumberKind)vcardTypeItem).ToString()); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TelephoneNumber"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 0fac1a897..00c4ad377 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Term = CDP4Common.DTO.Term; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,571 @@ namespace CDP4JsonSerializer public class TermSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not Term term) + { + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(Term term) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](term.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), term.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](term.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](term.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](term.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](term.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](term.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](term.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](term.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](term.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](term.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](term.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](term.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(term.Actor.HasValue) + { + writer.WriteStringValue(term.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var term = thing as Term; - if (term == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Term."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(term); + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Term"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index ff548fa02..daafd885e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextParameterType = CDP4Common.DTO.TextParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class TextParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not TextParameterType textParameterType) + { + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TextParameterType textParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](textParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](textParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](textParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](textParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](textParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](textParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(textParameterType.Actor.HasValue) + { + writer.WriteStringValue(textParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var textParameterType = thing as TextParameterType; - if (textParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TextParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(textParameterType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index a17ccf915..132af6d3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextualNote = CDP4Common.DTO.TextualNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,512 @@ namespace CDP4JsonSerializer public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not TextualNote textualNote) + { + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TextualNote textualNote) - { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](textualNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textualNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](textualNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](textualNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textualNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textualNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textualNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](textualNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textualNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textualNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](textualNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textualNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textualNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textualNote.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(textualNote.Actor.HasValue) + { + writer.WriteStringValue(textualNote.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var textualNote = thing as TextualNote; - if (textualNote == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TextualNote."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(textualNote); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextualNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index f04cdb6e4..aca7ec451 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TimeOfDayParameterType = CDP4Common.DTO.TimeOfDayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +51,653 @@ namespace CDP4JsonSerializer public class TimeOfDayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not TimeOfDayParameterType timeOfDayParameterType) + { + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(TimeOfDayParameterType timeOfDayParameterType) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](timeOfDayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](timeOfDayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), timeOfDayParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](timeOfDayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](timeOfDayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](timeOfDayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](timeOfDayParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](timeOfDayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](timeOfDayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](timeOfDayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](timeOfDayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](timeOfDayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](timeOfDayParameterType.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(timeOfDayParameterType.Actor.HasValue) + { + writer.WriteStringValue(timeOfDayParameterType.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var timeOfDayParameterType = thing as TimeOfDayParameterType; - if (timeOfDayParameterType == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TimeOfDayParameterType."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(timeOfDayParameterType); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TimeOfDayParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index ec3683e88..5e29c196b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitFactor = CDP4Common.DTO.UnitFactor; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - }; + if (thing is not UnitFactor unitFactor) + { + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UnitFactor unitFactor) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](unitFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitFactor.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitFactor.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](unitFactor.Unit)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(unitFactor.Actor.HasValue) + { + writer.WriteStringValue(unitFactor.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var unitFactor = thing as UnitFactor; - if (unitFactor == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UnitFactor."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "exponent": + if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(unitFactor); + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitFactor"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 0f7d773d6..9bed99333 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitPrefix = CDP4Common.DTO.UnitPrefix; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +51,598 @@ namespace CDP4JsonSerializer public class UnitPrefixSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not UnitPrefix unitPrefix) + { + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UnitPrefix unitPrefix) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](unitPrefix.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitPrefix.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](unitPrefix.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](unitPrefix.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitPrefix.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitPrefix.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](unitPrefix.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitPrefix.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](unitPrefix.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitPrefix.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](unitPrefix.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitPrefix.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](unitPrefix.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitPrefix.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(unitPrefix.Actor.HasValue) + { + writer.WriteStringValue(unitPrefix.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var unitPrefix = thing as UnitPrefix; - if (unitPrefix == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UnitPrefix."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } - return this.Serialize(unitPrefix); + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitPrefix"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 8135775aa..017bf8548 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserPreference = CDP4Common.DTO.UserPreference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +51,379 @@ namespace CDP4JsonSerializer public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + if (thing is not UserPreference userPreference) + { + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UserPreference userPreference) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userPreference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userPreference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userPreference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userPreference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userPreference.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userPreference.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](userPreference.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userPreference.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](userPreference.Value)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userPreference.Actor.HasValue) + { + writer.WriteStringValue(userPreference.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var userPreference = thing as UserPreference; - if (userPreference == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UserPreference."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(userPreference); + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserPreference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index 89559bfca..e7d7b52e7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserRuleVerification = CDP4Common.DTO.UserRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -45,75 +51,524 @@ namespace CDP4JsonSerializer public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JValue(rule) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + if (thing is not UserRuleVerification userRuleVerification) + { + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(UserRuleVerification userRuleVerification) - { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](userRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](userRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userRuleVerification.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userRuleVerification.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](userRuleVerification.Rule)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), userRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userRuleVerification.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.0.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(userRuleVerification.Actor.HasValue) + { + writer.WriteStringValue(userRuleVerification.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if(userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var userRuleVerification = thing as UserRuleVerification; - if (userRuleVerification == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UserRuleVerification."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); + + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "executedon": + if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(userRuleVerification); + break; + case "isactive": + if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("rule"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violation": + if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("violation"u8); + + if(value is IEnumerable objectListViolation) + { + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + } + + writer.WriteEndArray(); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserRuleVerification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 8dab8e54f..9841c2313 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +29,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ValueGroup = CDP4Common.DTO.ValueGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +51,550 @@ namespace CDP4JsonSerializer public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// Serializes a into an /// - private readonly Dictionary> propertySerializerMap = new Dictionary> + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } - /// - /// Serialize the - /// - /// The to serialize - /// The - private JObject Serialize(ValueGroup valueGroup) - { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](valueGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](valueGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), valueGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](valueGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](valueGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](valueGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](valueGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](valueGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](valueGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](valueGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](valueGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](valueGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](valueGroup.ThingPreference)); - return jsonObject; - } + if (requestedDataModelVersion < Version.Parse("1.1.0")) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); + return; + } - /// - /// Gets the map containing the serialization method for each property of the class. - /// - public IReadOnlyDictionary> PropertySerializerMap - { - get { return this.propertySerializerMap; } + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.3.0"); + writer.WritePropertyName("actor"u8); + + if(valueGroup.Actor.HasValue) + { + writer.WriteStringValue(valueGroup.Actor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) - { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); - } + var requestedVersion = requestedDataModelVersion.ToString(3); - var valueGroup = thing as ValueGroup; - if (valueGroup == null) + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ValueGroup."); - } + case "actor": + if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("actor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "alias": + if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("alias"u8); + + if(value is IEnumerable objectListAlias) + { + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + } + + writer.WriteEndArray(); + break; + case "category": + if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("category"u8); + + if(value is IEnumerable objectListCategory) + { + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + } + + writer.WriteEndArray(); + break; + case "classkind": + if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("definition"u8); + + if(value is IEnumerable objectListDefinition) + { + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + } + + writer.WriteEndArray(); + break; + case "excludeddomain": + if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(valueGroup); + if(value is IEnumerable objectListExcludedDomain) + { + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + } + + writer.WriteEndArray(); + break; + case "excludedperson": + if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("excludedPerson"u8); + + if(value is IEnumerable objectListExcludedPerson) + { + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + } + + writer.WriteEndArray(); + break; + case "hyperlink": + if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) + { + return; + } + + writer.WriteStartArray("hyperLink"u8); + + if(value is IEnumerable objectListHyperLink) + { + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + } + + writer.WriteEndArray(); + break; + case "iid": + if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) + { + return; + } + + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ValueGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } From 64d272176cf15b4486f8c7c1ba6eda11d1f51147 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Thu, 24 Oct 2024 11:54:37 +0200 Subject: [PATCH 17/34] Bump version number and fix errors --- CDP4Common/CDP4Common.csproj | 2 +- CDP4Dal.Tests/Operations/OperationTestFixture.cs | 2 ++ CDP4Dal/CDP4Dal.csproj | 2 +- CDP4DalCommon/CDP4DalCommon.csproj | 2 +- CDP4JsonFileDal/CDP4JsonFileDal.csproj | 2 +- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 6 +++--- CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj | 2 +- CDP4Reporting/CDP4Reporting.csproj | 2 +- .../CDP4RequirementsVerification.csproj | 2 +- CDP4Rules/CDP4Rules.csproj | 2 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 2 +- CDP4ServicesDal/CdpPostOperation.cs | 3 +-- CDP4ServicesDal/CdpServicesDal.cs | 2 -- CDP4ServicesDal/ValueSetOperationCreator.cs | 3 +-- CDP4ServicesMessaging/CDP4ServicesMessaging.csproj | 2 +- CDP4Web/CDP4Web.csproj | 2 +- .../Operations/WSPPostOperationTestFixture.cs | 3 +-- CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs | 5 ++--- CDP4WspDal/CDP4WspDal.csproj | 2 +- CDP4WspDal/CopyOperationHandler.cs | 3 +-- CDP4WspDal/ValueSetOperationCreator.cs | 3 +-- CDP4WspDal/WSPPostOperation.cs | 3 +-- 22 files changed, 25 insertions(+), 32 deletions(-) diff --git a/CDP4Common/CDP4Common.csproj b/CDP4Common/CDP4Common.csproj index ac05277d4..4e0bcce76 100644 --- a/CDP4Common/CDP4Common.csproj +++ b/CDP4Common/CDP4Common.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Common Community Edition - 27.4.0 + 28.0.0 CDP4 Common Class Library that contains DTOs, POCOs Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed diff --git a/CDP4Dal.Tests/Operations/OperationTestFixture.cs b/CDP4Dal.Tests/Operations/OperationTestFixture.cs index eefe10a1b..5048f43bb 100644 --- a/CDP4Dal.Tests/Operations/OperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/OperationTestFixture.cs @@ -28,6 +28,8 @@ namespace CDP4Dal.Tests using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index 0c52a98e2..2546d617f 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Dal Community Edition - 27.4.0 + 28.0.0 CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj index 65793335c..a3e4c54ca 100644 --- a/CDP4DalCommon/CDP4DalCommon.csproj +++ b/CDP4DalCommon/CDP4DalCommon.csproj @@ -5,7 +5,7 @@ Starion Group S.A. latest CDP4DalCommon Community Edition - 27.4.0 + 28.0.0 CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 0f0728bf3..52faff2c4 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4JsonFileDal Community Edition - 27.4.0 + 28.0.0 CDP4 Json File Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 2878f5551..8bc8f9849 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4JsonSerializer Community Edition - 27.4.0 + 28.0.0 CDP4 JSON Serialization Library Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael @@ -28,8 +28,8 @@ - - + + diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index b1e8cf8a7..5d4ef7750 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4MessagePackSerializer Community Edition - 27.4.0 + 28.0.0 CDP4 MessagePack Serialization Library Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar diff --git a/CDP4Reporting/CDP4Reporting.csproj b/CDP4Reporting/CDP4Reporting.csproj index 687103b22..03f21f677 100644 --- a/CDP4Reporting/CDP4Reporting.csproj +++ b/CDP4Reporting/CDP4Reporting.csproj @@ -4,7 +4,7 @@ netstandard2.0 Starion Group S.A. CDP4Reporting Community Edition - 27.4.0 + 28.0.0 CDP4 Reporting Copyright © Starion Group S.A. Sam, Alex, Alexander diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj index 43b8506f8..c2fa0ae7b 100644 --- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj +++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4RequirementsVerification Community Edition - 27.4.0 + 28.0.0 CDP4 Class Library that provides requirement verification Copyright © Starion Group S.A. Sam, Alex, Alexander, Yevhen, Nathanael diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj index 641874090..17116abc5 100644 --- a/CDP4Rules/CDP4Rules.csproj +++ b/CDP4Rules/CDP4Rules.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Rules Community Edition - 27.4.0 + 28.0.0 CDP4 Class Library that provides Model Analysis and Rule Checking Copyright © Starion Group S.A. Sam, Alex, Alexander, Yevhen, Nathanael diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 9c84e0cd1..58b800644 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4ServicesDal Community Edition - 27.4.0 + 28.0.0 CDP4ServicesDal Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael diff --git a/CDP4ServicesDal/CdpPostOperation.cs b/CDP4ServicesDal/CdpPostOperation.cs index 6780481aa..7c493e2f6 100644 --- a/CDP4ServicesDal/CdpPostOperation.cs +++ b/CDP4ServicesDal/CdpPostOperation.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2019 Starion Group S.A. // diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index 5534f7a62..8d2a32dda 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -44,8 +44,6 @@ namespace CDP4ServicesDal using CDP4Common.DTO; using CDP4Common.Extensions; - using CDP4DalCommon.Tasks; - using CDP4Dal; using CDP4Dal.Composition; using CDP4Dal.DAL; diff --git a/CDP4ServicesDal/ValueSetOperationCreator.cs b/CDP4ServicesDal/ValueSetOperationCreator.cs index c1d28be8d..bde85c07c 100644 --- a/CDP4ServicesDal/ValueSetOperationCreator.cs +++ b/CDP4ServicesDal/ValueSetOperationCreator.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index 211e3d6d8..034b83958 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -4,7 +4,7 @@ netstandard2.0 Starion Group S.A. CDP4Common Community Edition - 27.4.0 + 28.0.0 CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj index d81e648c9..52679ed94 100644 --- a/CDP4Web/CDP4Web.csproj +++ b/CDP4Web/CDP4Web.csproj @@ -5,7 +5,7 @@ latest Starion Group S.A. CDP4Web Community Edition - 27.4.0 + 28.0.0 CDP4Web Dedicated Sdk for CDPServicesDal Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime diff --git a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs index a3b35fab3..65eda2928 100644 --- a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // diff --git a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs index a3b35fab3..c35b7fa69 100644 --- a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // @@ -21,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// ------------------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests.Operations { diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index 868ae8d5c..f871a0c2e 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4WspDal Community Edition - 27.4.0 + 28.0.0 CDP4 WSP Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael diff --git a/CDP4WspDal/CopyOperationHandler.cs b/CDP4WspDal/CopyOperationHandler.cs index 452f38049..95647049e 100644 --- a/CDP4WspDal/CopyOperationHandler.cs +++ b/CDP4WspDal/CopyOperationHandler.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // diff --git a/CDP4WspDal/ValueSetOperationCreator.cs b/CDP4WspDal/ValueSetOperationCreator.cs index 109bdb2ad..6fa466b67 100644 --- a/CDP4WspDal/ValueSetOperationCreator.cs +++ b/CDP4WspDal/ValueSetOperationCreator.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // diff --git a/CDP4WspDal/WSPPostOperation.cs b/CDP4WspDal/WSPPostOperation.cs index ddb8667d0..c5c170d97 100644 --- a/CDP4WspDal/WSPPostOperation.cs +++ b/CDP4WspDal/WSPPostOperation.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // From f7ddc665ccdc1993bccbf8d66894c481bd20f232 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Fri, 25 Oct 2024 16:59:08 +0200 Subject: [PATCH 18/34] Story so far --- .../Protocol/Operations/PostOperation.cs | 29 +- .../CDP4DalJsonSerializer.csproj | 2 +- .../ActionItemSerializer.cs | 365 +++--- .../ActualFiniteStateListSerializer.cs | 294 +++-- .../ActualFiniteStateSerializer.cs | 171 ++- .../AutoGenDtoSerializer/AliasSerializer.cs | 106 +- .../AndExpressionSerializer.cs | 171 ++- .../ApprovalSerializer.cs | 106 +- .../ArrayParameterTypeSerializer.cs | 481 ++++--- .../BinaryNoteSerializer.cs | 157 ++- .../BinaryRelationshipRuleSerializer.cs | 302 +++-- .../BinaryRelationshipSerializer.cs | 223 ++-- .../AutoGenDtoSerializer/BookSerializer.cs | 203 +-- .../BooleanParameterTypeSerializer.cs | 367 +++--- .../AutoGenDtoSerializer/BoundsSerializer.cs | 106 +- .../BuiltInRuleVerificationSerializer.cs | 171 ++- .../CategorySerializer.cs | 434 ++++--- .../ChangeProposalSerializer.cs | 365 +++--- .../ChangeRequestSerializer.cs | 365 +++--- .../CitationSerializer.cs | 106 +- .../AutoGenDtoSerializer/ColorSerializer.cs | 106 +- .../CommonFileStoreSerializer.cs | 236 ++-- .../CompoundParameterTypeSerializer.cs | 424 ++++--- .../ConstantSerializer.cs | 367 +++--- .../ContractChangeNoticeSerializer.cs | 365 +++--- .../CyclicRatioScaleSerializer.cs | 432 ++++--- .../DateParameterTypeSerializer.cs | 367 +++--- .../DateTimeParameterTypeSerializer.cs | 367 +++--- .../DecompositionRuleSerializer.cs | 367 +++--- .../DefinitionSerializer.cs | 286 +++-- ...endentParameterTypeAssignmentSerializer.cs | 78 +- .../DerivedQuantityKindSerializer.cs | 489 +++++--- .../DerivedUnitSerializer.cs | 359 ++++-- .../DiagramCanvasSerializer.cs | 209 +-- .../DiagramEdgeSerializer.cs | 308 +++-- .../DiagramObjectSerializer.cs | 263 ++-- .../DomainFileStoreSerializer.cs | 236 ++-- .../DomainOfExpertiseGroupSerializer.cs | 367 +++--- .../DomainOfExpertiseSerializer.cs | 367 +++--- .../ElementDefinitionSerializer.cs | 664 ++++++---- .../ElementUsageSerializer.cs | 497 +++++--- .../EmailAddressSerializer.cs | 106 +- ...eeringModelDataDiscussionItemSerializer.cs | 106 +- .../EngineeringModelDataNoteSerializer.cs | 211 ++-- .../EngineeringModelSerializer.cs | 449 ++++--- .../EngineeringModelSetupSerializer.cs | 601 +++++---- .../EnumerationParameterTypeSerializer.cs | 424 ++++--- .../EnumerationValueDefinitionSerializer.cs | 302 +++-- .../ExclusiveOrExpressionSerializer.cs | 171 ++- .../ExternalIdentifierMapSerializer.cs | 171 ++- .../FileRevisionSerializer.cs | 163 ++- .../AutoGenDtoSerializer/FileSerializer.cs | 237 ++-- .../FileTypeSerializer.cs | 367 +++--- .../AutoGenDtoSerializer/FolderSerializer.cs | 106 +- .../GlossarySerializer.cs | 432 ++++--- .../AutoGenDtoSerializer/GoalSerializer.cs | 311 +++-- .../HyperLinkSerializer.cs | 106 +- .../IdCorrespondenceSerializer.cs | 106 +- ...endentParameterTypeAssignmentSerializer.cs | 78 +- .../IntervalScaleSerializer.cs | 432 ++++--- .../IterationSerializer.cs | 1116 ++++++++++------- .../IterationSetupSerializer.cs | 106 +- .../LinearConversionUnitSerializer.cs | 302 +++-- .../LogEntryChangelogItemSerializer.cs | 117 +- .../LogarithmicScaleSerializer.cs | 497 +++++--- .../MappingToReferenceScaleSerializer.cs | 106 +- .../ModelLogEntrySerializer.cs | 347 +++-- .../ModelReferenceDataLibrarySerializer.cs | 1074 ++++++++++------ .../ModellingThingReferenceSerializer.cs | 106 +- .../MultiRelationshipRuleSerializer.cs | 367 +++--- .../MultiRelationshipSerializer.cs | 288 +++-- .../NaturalLanguageSerializer.cs | 106 +- .../NestedElementSerializer.cs | 228 ++-- .../NestedParameterSerializer.cs | 106 +- .../NotExpressionSerializer.cs | 106 +- .../AutoGenDtoSerializer/OptionSerializer.cs | 432 ++++--- .../OrExpressionSerializer.cs | 171 ++- .../OrdinalScaleSerializer.cs | 432 ++++--- .../OrganizationSerializer.cs | 106 +- .../OrganizationalParticipantSerializer.cs | 78 +- .../OwnedStyleSerializer.cs | 158 ++- .../AutoGenDtoSerializer/PageSerializer.cs | 203 +-- .../ParameterGroupSerializer.cs | 109 +- .../ParameterOverrideSerializer.cs | 236 ++-- .../ParameterOverrideValueSetSerializer.cs | 106 +- .../ParameterSerializer.cs | 238 ++-- .../ParameterSubscriptionSerializer.cs | 171 ++- ...ParameterSubscriptionValueSetSerializer.cs | 106 +- .../ParameterTypeComponentSerializer.cs | 106 +- .../ParameterValueSetSerializer.cs | 106 +- .../ParameterizedCategoryRuleSerializer.cs | 367 +++--- .../ParametricConstraintSerializer.cs | 171 ++- .../ParticipantPermissionSerializer.cs | 106 +- .../ParticipantRoleSerializer.cs | 367 +++--- .../ParticipantSerializer.cs | 171 ++- .../PersonPermissionSerializer.cs | 106 +- .../PersonRoleSerializer.cs | 367 +++--- .../AutoGenDtoSerializer/PersonSerializer.cs | 305 +++-- .../AutoGenDtoSerializer/PointSerializer.cs | 106 +- .../PossibleFiniteStateListSerializer.cs | 428 ++++--- .../PossibleFiniteStateSerializer.cs | 302 +++-- .../PrefixedUnitSerializer.cs | 302 +++-- .../PublicationSerializer.cs | 236 ++-- .../QuantityKindFactorSerializer.cs | 106 +- .../RatioScaleSerializer.cs | 432 ++++--- .../ReferenceSourceSerializer.cs | 367 +++--- .../ReferencerRuleSerializer.cs | 367 +++--- .../RelationalExpressionSerializer.cs | 106 +- .../RelationshipParameterValueSerializer.cs | 106 +- .../RequestForDeviationSerializer.cs | 365 +++--- .../RequestForWaiverSerializer.cs | 365 +++--- .../RequirementSerializer.cs | 493 +++++--- ...ementsContainerParameterValueSerializer.cs | 106 +- .../RequirementsGroupSerializer.cs | 469 ++++--- .../RequirementsSpecificationSerializer.cs | 534 +++++--- .../ReviewItemDiscrepancySerializer.cs | 416 +++--- .../RuleVerificationListSerializer.cs | 359 ++++-- .../RuleViolationSerializer.cs | 173 ++- .../SampledFunctionParameterTypeSerializer.cs | 295 +++-- .../ScaleReferenceQuantityValueSerializer.cs | 106 +- .../ScaleValueDefinitionSerializer.cs | 302 +++-- .../AutoGenDtoSerializer/SectionSerializer.cs | 203 +-- .../SharedStyleSerializer.cs | 158 ++- .../SimpleParameterValueSerializer.cs | 106 +- .../SimpleQuantityKindSerializer.cs | 432 ++++--- .../SimpleUnitSerializer.cs | 302 +++-- .../SiteDirectoryDataAnnotationSerializer.cs | 208 +-- ...teDirectoryDataDiscussionItemSerializer.cs | 106 +- .../SiteDirectorySerializer.cs | 812 +++++++----- .../SiteDirectoryThingReferenceSerializer.cs | 106 +- .../SiteLogEntrySerializer.cs | 347 +++-- .../SiteReferenceDataLibrarySerializer.cs | 1074 ++++++++++------ .../SolutionSerializer.cs | 106 +- .../SpecializedQuantityKindSerializer.cs | 432 ++++--- .../StakeHolderValueMapSerializer.cs | 566 +++++---- .../StakeHolderValueMapSettingsSerializer.cs | 106 +- .../StakeholderSerializer.cs | 362 +++--- .../StakeholderValueSerializer.cs | 311 +++-- .../TelephoneNumberSerializer.cs | 173 ++- .../AutoGenDtoSerializer/TermSerializer.cs | 302 +++-- .../TextParameterTypeSerializer.cs | 367 +++--- .../TextualNoteSerializer.cs | 158 ++- .../TimeOfDayParameterTypeSerializer.cs | 367 +++--- .../UnitFactorSerializer.cs | 106 +- .../UnitPrefixSerializer.cs | 302 +++-- .../UserPreferenceSerializer.cs | 106 +- .../UserRuleVerificationSerializer.cs | 171 ++- .../ValueGroupSerializer.cs | 311 +++-- CDP4JsonSerializer/Helper/SerializerHelper.cs | 5 +- pre-release.bat | 2 +- 150 files changed, 25050 insertions(+), 16145 deletions(-) diff --git a/CDP4DalCommon/Protocol/Operations/PostOperation.cs b/CDP4DalCommon/Protocol/Operations/PostOperation.cs index d43e3b916..d73009864 100644 --- a/CDP4DalCommon/Protocol/Operations/PostOperation.cs +++ b/CDP4DalCommon/Protocol/Operations/PostOperation.cs @@ -36,25 +36,46 @@ namespace CDP4DalCommon.Protocol.Operations /// public class PostOperation { + private List delete = []; + private List create = []; + private List update = []; + private List copy = []; + /// /// Gets or sets the collection of DTOs to delete. /// - public List Delete { get; set; } = []; + public List Delete + { + get => this.delete ?? []; + set => this.delete = value ?? []; + } /// /// Gets or sets the collection of DTOs to create. /// - public List Create { get; set; } = []; + public List Create + { + get => this.create ?? []; + set => this.create = value ?? []; + } /// /// Gets or sets the collection of DTOs to update. /// - public List Update { get; set; } = []; + public List Update + { + get => this.update ?? []; + set => this.update = value ?? []; + } /// /// Gets or sets the collection of DTOs to copy. /// - public List Copy { get; set; } = []; + public List Copy + { + get => this.copy ?? []; + set => this.copy = value ?? []; + } /// /// Populate the current with the content based on the diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj index 0d369da52..d81af2ef6 100644 --- a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj +++ b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj @@ -5,7 +5,7 @@ RHEA System S.A. latest CDP4DalJsonSerializer Community Edition - 26.6.0 + 28.0.0 JsonSerializer for the CDP4DalCommon types Copyright © RHEA System S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 1084b3f83..40fc2cb56 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,25 +79,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.1.0"); writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -120,34 +128,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -168,27 +188,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (actionItem.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (actionItem.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -199,25 +226,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.2.0"); writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -240,34 +275,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -288,27 +335,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (actionItem.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (actionItem.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -332,25 +386,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -373,34 +434,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + if (actionItem.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -421,27 +494,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (actionItem.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (actionItem.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -513,17 +593,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -549,17 +628,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classification": if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) @@ -675,17 +753,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "duedate": if(!AllowedVersionsPerProperty["dueDate"].Contains(requestedVersion)) @@ -711,17 +788,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -729,17 +805,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -837,17 +912,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -891,17 +965,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index b111405a9..d23dfcb90 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,81 +77,109 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); - writer.WriteStartArray("actualState"u8); - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ActualState.Count > 0) { - writer.WriteStringValue(actualStateItem); - } + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); - writer.WriteStartArray("actualState"u8); - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ActualState.Count > 0) { - writer.WriteStringValue(actualStateItem); - } + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -159,57 +187,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); - writer.WriteStartArray("actualState"u8); - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ActualState.Count > 0) { - writer.WriteStringValue(actualStateItem); - } + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -217,14 +265,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -244,43 +296,58 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("actualState"u8); - - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ActualState.Count > 0) { - writer.WriteStringValue(actualStateItem); - } + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteStateList.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -288,14 +355,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -347,17 +418,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("actualState"u8); - - if(value is IEnumerable objectListActualState) + if (value is IEnumerable objectListActualState && objectListActualState.Any()) { + writer.WriteStartArray("actualState"u8); + foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(actualStateItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -383,17 +453,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -401,17 +470,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeoption": if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) @@ -419,17 +487,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludeOption"u8); - - if(value is IEnumerable objectListExcludeOption) + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) { + writer.WriteStartArray("excludeOption"u8); + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludeOptionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -491,17 +558,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleFiniteStateList"u8); - - if(value is IEnumerable objectListPossibleFiniteStateList) + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) { + writer.WriteStartArray("possibleFiniteStateList"u8); + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(possibleFiniteStateListItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index f5addebc0..6d5b914ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -83,14 +83,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Iid); writer.WritePropertyName("kind"u8); writer.WriteStringValue(actualFiniteState.Kind.ToString()); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.PossibleState.Count > 0) { - writer.WriteStringValue(possibleStateItem); - } + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -99,23 +103,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -123,14 +135,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.PossibleState.Count > 0) { - writer.WriteStringValue(possibleStateItem); - } + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -139,23 +155,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -163,14 +187,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.PossibleState.Count > 0) { - writer.WriteStringValue(possibleStateItem); - } + writer.WriteStartArray("possibleState"u8); - writer.WriteEndArray(); + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -192,23 +220,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -216,14 +252,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + if (actualFiniteState.PossibleState.Count > 0) { - writer.WriteStringValue(possibleStateItem); - } + writer.WriteStartArray("possibleState"u8); - writer.WriteEndArray(); + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -293,17 +333,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -311,17 +350,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -383,17 +421,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleState"u8); - - if(value is IEnumerable objectListPossibleState) + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) { + writer.WriteStartArray("possibleState"u8); + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(possibleStateItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index f9f993a00..7745b7aad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -96,23 +96,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -131,23 +139,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -179,23 +195,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (alias.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -291,17 +315,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -309,17 +332,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index cba482db8..3b09ac6b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -83,37 +83,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (andExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -121,37 +133,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (andExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -159,14 +183,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (andExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); @@ -186,23 +214,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (andExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -210,14 +246,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (andExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); @@ -285,17 +325,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -303,17 +342,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -375,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("term"u8); - - if(value is IEnumerable objectListTerm) + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { + writer.WriteStartArray("term"u8); + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(termItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index c05f4dd9d..7ed2dd5fd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -87,23 +87,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -128,23 +136,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -182,23 +198,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (approval.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -348,17 +372,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -366,17 +389,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 99a8b199c..2bfbc8afe 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,61 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("dimension"u8); - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Dimension.Count > 0) { + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -152,79 +176,111 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("dimension"u8); - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Dimension.Count > 0) { + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -247,79 +303,111 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("dimension"u8); - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Dimension.Count > 0) { + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -355,79 +443,110 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("dimension"u8); - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + if (arrayParameterType.Dimension.Count > 0) { + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (arrayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -495,17 +614,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -513,17 +631,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -549,17 +666,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("component"u8); - - if(value is IEnumerable objectListComponent) + if (value is IEnumerable objectListComponent && objectListComponent.Any()) { + writer.WriteStartArray("component"u8); + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(componentItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definition": if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) @@ -567,17 +683,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "dimension": if(!AllowedVersionsPerProperty["dimension"].Contains(requestedVersion)) @@ -585,17 +700,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("dimension"u8); - - if(value is IEnumerable objectListDimension) + if (value is IEnumerable objectListDimension && objectListDimension.Any()) { + writer.WriteStartArray("dimension"u8); + foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(dimensionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -603,17 +717,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -621,17 +734,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -639,17 +751,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 4547107d4..f949f7920 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,36 +79,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.1.0"); writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -129,36 +141,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.2.0"); writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -192,36 +216,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -303,17 +339,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -357,17 +392,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -375,17 +409,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "filetype": if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 79fbf3310..367d6d45d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -129,54 +141,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -201,54 +233,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -286,54 +338,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -403,17 +474,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -439,17 +509,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -457,17 +526,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -475,17 +543,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "forwardrelationshipname": if(!AllowedVersionsPerProperty["forwardRelationshipName"].Contains(requestedVersion)) @@ -511,17 +578,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index a719d0883..72b614708 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); @@ -101,34 +105,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -136,14 +152,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -154,34 +174,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -191,14 +223,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -222,34 +258,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -259,14 +306,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (binaryRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -322,17 +373,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -358,17 +408,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -376,17 +425,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -466,17 +514,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterValue"u8); - - if(value is IEnumerable objectListParameterValue) + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { + writer.WriteStartArray("parameterValue"u8); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index abc6c6d35..2d94b798b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + if (book.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -118,50 +130,66 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + if (book.Section.Count > 0) { + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + if (book.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -173,14 +201,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + if (book.Section.Count > 0) { + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -200,36 +232,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + if (book.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (book.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -241,14 +284,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - writer.WriteStartArray("section"u8); - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + if (book.Section.Count > 0) { + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -300,17 +347,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -354,17 +400,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -372,17 +417,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -480,17 +524,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("section"u8); - - if(value is IEnumerable objectListSection) + if (value is IEnumerable objectListSection && objectListSection.Any()) { + writer.WriteStartArray("section"u8); + foreach(var sectionItem in objectListSection.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(sectionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shortname": if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index 60566d570..af83a0c67 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -130,61 +146,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -203,61 +243,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -289,61 +353,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (booleanParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +597,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index a20241ef0..cf2bb7be9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -118,23 +126,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -170,23 +186,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (bounds.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -270,17 +294,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -288,17 +311,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "height": if(!AllowedVersionsPerProperty["height"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 9ae30150d..8c036b3db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -100,37 +100,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -155,37 +167,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -212,14 +236,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(builtInRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); - writer.WriteEndArray(); + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -237,23 +265,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -280,14 +316,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(builtInRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (builtInRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); - writer.WriteEndArray(); + foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + } break; default: @@ -353,17 +393,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -371,17 +410,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "executedon": if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) @@ -533,17 +571,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("violation"u8); - - if(value is IEnumerable objectListViolation) + if (value is IEnumerable objectListViolation && objectListViolation.Any()) { + writer.WriteStartArray("violation"u8); + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(violationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the BuiltInRuleVerification"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index 92545d84e..a65412b7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + if (category.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + if (category.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (category.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -114,77 +126,105 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(category.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); - foreach(var permissibleClassItem in category.PermissibleClass) + if (category.PermissibleClass.Count > 0) { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + if (category.SuperCategory.Count > 0) { - writer.WriteStringValue(superCategoryItem); - } + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + if (category.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + if (category.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (category.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -196,77 +236,105 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); - foreach(var permissibleClassItem in category.PermissibleClass) + if (category.PermissibleClass.Count > 0) { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + writer.WriteStartArray("permissibleClass"u8); - writer.WriteEndArray(); + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + if (category.SuperCategory.Count > 0) { - writer.WriteStringValue(superCategoryItem); - } + writer.WriteStartArray("superCategory"u8); - writer.WriteEndArray(); + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + if (category.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + if (category.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (category.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -278,27 +346,35 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); - foreach(var permissibleClassItem in category.PermissibleClass) + if (category.PermissibleClass.Count > 0) { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + if (category.SuperCategory.Count > 0) { - writer.WriteStringValue(superCategoryItem); - } + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); @@ -316,52 +392,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + if (category.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + if (category.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (category.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (category.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -373,27 +468,35 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - writer.WriteStartArray("permissibleClass"u8); - foreach(var permissibleClassItem in category.PermissibleClass) + if (category.PermissibleClass.Count > 0) { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - writer.WriteStartArray("superCategory"u8); - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + if (category.SuperCategory.Count > 0) { - writer.WriteStringValue(superCategoryItem); - } + writer.WriteStartArray("superCategory"u8); - writer.WriteEndArray(); + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); @@ -443,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -479,17 +581,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -497,17 +598,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -515,17 +615,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -533,17 +632,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -641,17 +739,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("permissibleClass"u8); - - if(value is IEnumerable objectListPermissibleClass) + if (value is IEnumerable objectListPermissibleClass && objectListPermissibleClass.Any()) { - foreach(var permissibleClassItem in objectListPermissibleClass) + writer.WriteStartArray("permissibleClass"u8); + + foreach (var permissibleClassItem in objectListPermissibleClass) { writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -695,17 +792,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("superCategory"u8); - - if(value is IEnumerable objectListSuperCategory) + if (value is IEnumerable objectListSuperCategory && objectListSuperCategory.Any()) { + writer.WriteStartArray("superCategory"u8); + foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(superCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index f51c63661..d20de6222 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -107,32 +115,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -153,27 +173,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -182,25 +209,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -212,32 +247,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -258,27 +305,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -300,25 +354,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -330,32 +391,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -376,27 +449,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeProposal.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -450,17 +530,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -486,17 +565,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "changerequest": if(!AllowedVersionsPerProperty["changeRequest"].Contains(requestedVersion)) @@ -594,17 +672,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -612,17 +689,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -630,17 +706,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -738,17 +813,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -792,17 +866,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index a7b2b58e5..869705705 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -105,32 +113,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -151,27 +171,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -180,25 +207,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -208,32 +243,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -254,27 +301,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -296,25 +350,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -324,32 +385,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -370,27 +443,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (changeRequest.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -444,17 +524,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -480,17 +559,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classification": if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) @@ -570,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -588,17 +665,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -606,17 +682,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -714,17 +789,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -768,17 +842,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index 423ff51c3..fd1787c24 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -98,23 +98,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -137,23 +145,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -189,23 +205,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (citation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -289,17 +313,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -307,17 +330,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 24f898ef3..aaf18cec2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -98,23 +98,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -135,23 +143,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -185,23 +201,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (color.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -299,17 +323,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -317,17 +340,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "green": if(!AllowedVersionsPerProperty["green"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index f246db2b5..24f804f2f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -81,23 +81,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("file"u8); - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -114,41 +122,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -167,41 +191,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -233,41 +273,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (commonFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -363,17 +419,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -381,17 +436,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "file": if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) @@ -399,17 +453,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("file"u8); - - if(value is IEnumerable objectListFile) + if (value is IEnumerable objectListFile && objectListFile.Any()) { + writer.WriteStartArray("file"u8); + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(fileItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "folder": if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) @@ -417,17 +470,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("folder"u8); - - if(value is IEnumerable objectListFolder) + if (value is IEnumerable objectListFolder && objectListFolder.Any()) { + writer.WriteStartArray("folder"u8); + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(folderItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index 09cc7998b..c38e5d92f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,52 +77,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (compoundParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -141,70 +161,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (compoundParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -225,70 +273,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (compoundParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -322,70 +398,97 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - writer.WriteStartArray("component"u8); - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + if (compoundParameterType.Component.Count > 0) { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (compoundParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -451,17 +554,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -469,17 +571,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -505,17 +606,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("component"u8); - - if(value is IEnumerable objectListComponent) + if (value is IEnumerable objectListComponent && objectListComponent.Any()) { + writer.WriteStartArray("component"u8); + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(componentItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definition": if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) @@ -523,17 +623,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -541,17 +640,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -559,17 +657,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -577,17 +674,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index 412e656be..853f76c39 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + if (constant.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + if (constant.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + if (constant.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (constant.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -142,61 +158,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + if (constant.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + if (constant.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + if (constant.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (constant.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -227,61 +267,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + if (constant.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + if (constant.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + if (constant.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (constant.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -325,61 +389,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + if (constant.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + if (constant.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + if (constant.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (constant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (constant.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -455,17 +542,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -473,17 +559,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -509,17 +594,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -527,17 +611,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -545,17 +628,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -563,17 +645,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 8d6aaf3db..6b9fea444 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -107,32 +115,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -153,27 +173,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -182,25 +209,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -212,32 +247,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -258,27 +305,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -300,25 +354,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -330,32 +391,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -376,27 +449,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (contractChangeNotice.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -450,17 +530,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -486,17 +565,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "changeproposal": if(!AllowedVersionsPerProperty["changeProposal"].Contains(requestedVersion)) @@ -594,17 +672,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -612,17 +689,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -630,17 +706,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -738,17 +813,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -792,17 +866,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index e8a0f05f7..453204d86 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -143,64 +159,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -210,14 +250,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -241,64 +285,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -308,14 +376,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -341,14 +413,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -364,52 +440,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -419,14 +514,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -452,14 +551,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (cyclicRatioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -507,17 +610,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -543,17 +645,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -561,17 +662,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -579,17 +679,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -597,17 +696,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -687,17 +785,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("mappingToReferenceScale"u8); - - if(value is IEnumerable objectListMappingToReferenceScale) + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { + writer.WriteStartArray("mappingToReferenceScale"u8); + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(mappingToReferenceScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "maximumpermissiblevalue": if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) @@ -921,17 +1018,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the CyclicRatioScale"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 9e479ed0c..6d9a7f002 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -130,61 +146,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -203,61 +243,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -289,61 +353,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +597,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index c75c8db26..c8662ba45 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -130,61 +146,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -203,61 +243,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -289,61 +353,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (dateTimeParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +597,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index 1bcb6fc13..aec54665d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ContainedCategory.Count > 0) { - writer.WriteStringValue(containedCategoryItem); - } + writer.WriteStartArray("containedCategory"u8); - writer.WriteEndArray(); + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -143,63 +159,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ContainedCategory.Count > 0) { - writer.WriteStringValue(containedCategoryItem); - } + writer.WriteStartArray("containedCategory"u8); - writer.WriteEndArray(); + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -229,63 +269,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ContainedCategory.Count > 0) { - writer.WriteStringValue(containedCategoryItem); - } + writer.WriteStartArray("containedCategory"u8); - writer.WriteEndArray(); + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -328,63 +392,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - writer.WriteStartArray("containedCategory"u8); - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ContainedCategory.Count > 0) { - writer.WriteStringValue(containedCategoryItem); - } + writer.WriteStartArray("containedCategory"u8); - writer.WriteEndArray(); + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (decompositionRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -459,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -495,17 +581,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("containedCategory"u8); - - if(value is IEnumerable objectListContainedCategory) + if (value is IEnumerable objectListContainedCategory && objectListContainedCategory.Any()) { + writer.WriteStartArray("containedCategory"u8); + foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(containedCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "containingcategory": if(!AllowedVersionsPerProperty["containingCategory"].Contains(requestedVersion)) @@ -531,17 +616,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -549,17 +633,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -567,17 +650,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -585,17 +667,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 8554d8d6e..061f77804 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,85 +77,113 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); - writer.WriteStartArray("citation"u8); - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + if (definition.Citation.Count > 0) { - writer.WriteStringValue(citationItem); - } + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - writer.WriteStartArray("example"u8); - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Example.Count > 0) { + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); writer.WriteStringValue(definition.LanguageCode); - writer.WriteStartArray("note"u8); - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); - writer.WriteStartArray("citation"u8); - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + if (definition.Citation.Count > 0) { - writer.WriteStringValue(citationItem); - } + writer.WriteStartArray("citation"u8); - writer.WriteEndArray(); + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - writer.WriteStartArray("example"u8); - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Example.Count > 0) { + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -163,59 +191,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("note"u8); - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); - writer.WriteStartArray("citation"u8); - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + if (definition.Citation.Count > 0) { - writer.WriteStringValue(citationItem); - } + writer.WriteStartArray("citation"u8); - writer.WriteEndArray(); + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - writer.WriteStartArray("example"u8); - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Example.Count > 0) { + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -223,14 +271,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("note"u8); - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -250,45 +302,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("citation"u8); - - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + if (definition.Citation.Count > 0) { - writer.WriteStringValue(citationItem); - } + writer.WriteStartArray("citation"u8); - writer.WriteEndArray(); + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - writer.WriteStartArray("example"u8); - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Example.Count > 0) { + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (definition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -296,14 +363,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("note"u8); - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (definition.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -355,17 +426,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("citation"u8); - - if(value is IEnumerable objectListCitation) + if (value is IEnumerable objectListCitation && objectListCitation.Any()) { + writer.WriteStartArray("citation"u8); + foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(citationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -409,17 +479,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("example"u8); - - if(value is IEnumerable objectListExample) + if (value is IEnumerable objectListExample && objectListExample.Any()) { + writer.WriteStartArray("example"u8); + foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(exampleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -427,17 +496,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -445,17 +513,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -517,17 +584,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("note"u8); - - if(value is IEnumerable objectListNote) + if (value is IEnumerable objectListNote && objectListNote.Any()) { + writer.WriteStartArray("note"u8); + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(noteItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 9242d2ad8..cb1753bc2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); @@ -134,23 +142,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); @@ -237,17 +253,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -255,17 +270,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index f44c6f3fe..d2e722d3c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -123,25 +139,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); - writer.WriteEndArray(); + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedQuantityKind.QuantityKindFactor.Count > 0) { + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -152,63 +176,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -218,25 +266,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedQuantityKind.QuantityKindFactor.Count > 0) { + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -247,63 +303,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -313,25 +393,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedQuantityKind.QuantityKindFactor.Count > 0) { + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -355,63 +443,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -421,25 +532,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (derivedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - writer.WriteStartArray("quantityKindFactor"u8); - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedQuantityKind.QuantityKindFactor.Count > 0) { + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -495,17 +614,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -513,17 +631,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -567,17 +684,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -585,17 +701,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -603,17 +718,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -621,17 +735,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -711,17 +824,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleScale"u8); - - if(value is IEnumerable objectListPossibleScale) + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { + writer.WriteStartArray("possibleScale"u8); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "quantitydimensionsymbol": if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) @@ -747,17 +859,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("quantityKindFactor"u8); - - if(value is IEnumerable objectListQuantityKindFactor) + if (value is IEnumerable objectListQuantityKindFactor && objectListQuantityKindFactor.Any()) { + writer.WriteStartArray("quantityKindFactor"u8); + foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(quantityKindFactorItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index 100c65783..35f715ff3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -116,64 +128,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(derivedUnit.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); - writer.WriteStartArray("unitFactor"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedUnit.UnitFactor.Count > 0) { + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -187,64 +223,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(derivedUnit.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); - writer.WriteStartArray("unitFactor"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedUnit.UnitFactor.Count > 0) { + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -260,14 +320,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedUnit.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); - writer.WriteStartArray("unitFactor"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedUnit.UnitFactor.Count > 0) { + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -283,52 +347,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (derivedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -344,14 +427,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedUnit.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); - writer.WriteStartArray("unitFactor"u8); - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + if (derivedUnit.UnitFactor.Count > 0) { + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -435,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -633,17 +715,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("unitFactor"u8); - - if(value is IEnumerable objectListUnitFactor) + if (value is IEnumerable objectListUnitFactor && objectListUnitFactor.Any()) { + writer.WriteStartArray("unitFactor"u8); + foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(unitFactorItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index f63fa3c49..00d1faf15 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -128,45 +144,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); - writer.WriteEndArray(); + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); - writer.WriteEndArray(); + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -192,45 +224,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramCanvas.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -288,17 +335,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("bounds"u8); - - if(value is IEnumerable objectListBounds) + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { + writer.WriteStartArray("bounds"u8); + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(boundsItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -342,17 +388,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("diagramElement"u8); - - if(value is IEnumerable objectListDiagramElement) + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { + writer.WriteStartArray("diagramElement"u8); + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(diagramElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -360,17 +405,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -378,17 +422,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index bd83b5099..44ee73ce4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -99,56 +103,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); - writer.WriteEndArray(); + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - writer.WriteStartArray("point"u8); - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + if (diagramEdge.Point.Count > 0) { + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -170,14 +193,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -192,56 +219,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); - writer.WriteEndArray(); + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - writer.WriteStartArray("point"u8); - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + if (diagramEdge.Point.Count > 0) { + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -276,14 +322,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -298,56 +347,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramEdge.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - writer.WriteStartArray("point"u8); - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + if (diagramEdge.Point.Count > 0) { + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -414,17 +482,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("bounds"u8); - - if(value is IEnumerable objectListBounds) + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { + writer.WriteStartArray("bounds"u8); + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(boundsItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -468,17 +535,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("diagramElement"u8); - - if(value is IEnumerable objectListDiagramElement) + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { + writer.WriteStartArray("diagramElement"u8); + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(diagramElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -486,17 +552,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -504,17 +569,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -540,17 +604,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("localStyle"u8); - - if(value is IEnumerable objectListLocalStyle) + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) { + writer.WriteStartArray("localStyle"u8); + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(localStyleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) @@ -594,17 +657,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("point"u8); - - if(value is IEnumerable objectListPoint) + if (value is IEnumerable objectListPoint && objectListPoint.Any()) { + writer.WriteStartArray("point"u8); + foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(pointItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 8c6f2971d..414c594bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); - writer.WriteEndArray(); + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -99,45 +103,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); - writer.WriteEndArray(); + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); - writer.WriteEndArray(); + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -161,14 +180,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -183,45 +206,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); - writer.WriteEndArray(); + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); - writer.WriteEndArray(); + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -258,14 +296,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.Bounds.Count > 0) { - writer.WriteStringValue(boundsItem); - } + writer.WriteStartArray("bounds"u8); - writer.WriteEndArray(); + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -280,45 +321,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.DiagramElement.Count > 0) { - writer.WriteStringValue(diagramElementItem); - } + writer.WriteStartArray("diagramElement"u8); - writer.WriteEndArray(); + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - writer.WriteStartArray("localStyle"u8); - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + if (diagramObject.LocalStyle.Count > 0) { - writer.WriteStringValue(localStyleItem); - } + writer.WriteStartArray("localStyle"u8); - writer.WriteEndArray(); + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -387,17 +443,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("bounds"u8); - - if(value is IEnumerable objectListBounds) + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { + writer.WriteStartArray("bounds"u8); + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(boundsItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -441,17 +496,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("diagramElement"u8); - - if(value is IEnumerable objectListDiagramElement) + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { + writer.WriteStartArray("diagramElement"u8); + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(diagramElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "documentation": if(!AllowedVersionsPerProperty["documentation"].Contains(requestedVersion)) @@ -477,17 +531,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -495,17 +548,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -531,17 +583,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("localStyle"u8); - - if(value is IEnumerable objectListLocalStyle) + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) { + writer.WriteStartArray("localStyle"u8); + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(localStyleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index 487b8d342..ef33f54c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -81,23 +81,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("file"u8); - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -116,41 +124,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -171,41 +195,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -239,41 +279,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("file"u8); - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.File.Count > 0) { - writer.WriteStringValue(fileItem); - } + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("folder"u8); - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + if (domainFileStore.Folder.Count > 0) { - writer.WriteStringValue(folderItem); - } + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -371,17 +427,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -389,17 +444,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "file": if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) @@ -407,17 +461,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("file"u8); - - if(value is IEnumerable objectListFile) + if (value is IEnumerable objectListFile && objectListFile.Any()) { + writer.WriteStartArray("file"u8); + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(fileItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "folder": if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) @@ -425,17 +478,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("folder"u8); - - if(value is IEnumerable objectListFolder) + if (value is IEnumerable objectListFolder && objectListFolder.Any()) { + writer.WriteStartArray("folder"u8); + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(folderItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index 0b6e75b6d..dadb841c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domain"u8); - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -128,61 +144,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domain"u8); - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -199,61 +239,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domain"u8); - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -283,61 +347,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domain"u8); - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertiseGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -435,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "domain": if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domain"u8); - - if(value is IEnumerable objectListDomain) + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { + writer.WriteStartArray("domain"u8); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -507,17 +589,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index 27e14bd41..5f129689c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -128,61 +144,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -199,61 +239,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -283,61 +347,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (domainOfExpertise.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -417,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -507,17 +589,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index dfb690303..151de2db4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,52 +77,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ContainedElement.Count > 0) { - writer.WriteStringValue(containedElementItem); - } + writer.WriteStartArray("containedElement"u8); - writer.WriteEndArray(); + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -130,32 +150,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Parameter.Count > 0) { - writer.WriteStringValue(parameterItem); - } + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("parameterGroup"u8); - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ParameterGroup.Count > 0) { - writer.WriteStringValue(parameterGroupItem); - } + writer.WriteStartArray("parameterGroup"u8); - writer.WriteEndArray(); + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referencedElement"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ReferencedElement.Count > 0) { - writer.WriteStringValue(referencedElementItem); - } + writer.WriteStartArray("referencedElement"u8); - writer.WriteEndArray(); + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -164,70 +196,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ContainedElement.Count > 0) { - writer.WriteStringValue(containedElementItem); - } + writer.WriteStartArray("containedElement"u8); - writer.WriteEndArray(); + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -237,32 +297,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Parameter.Count > 0) { - writer.WriteStringValue(parameterItem); - } + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("parameterGroup"u8); - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ParameterGroup.Count > 0) { - writer.WriteStringValue(parameterGroupItem); - } + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("referencedElement"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ReferencedElement.Count > 0) { - writer.WriteStringValue(referencedElementItem); - } + writer.WriteStartArray("referencedElement"u8); - writer.WriteEndArray(); + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -271,70 +343,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ContainedElement.Count > 0) { - writer.WriteStringValue(containedElementItem); - } + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -342,43 +442,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); - writer.WriteStartArray("organizationalParticipant"u8); - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.OrganizationalParticipant.Count > 0) { - writer.WriteStringValue(organizationalParticipantItem); - } + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Parameter.Count > 0) { - writer.WriteStringValue(parameterItem); - } + writer.WriteStartArray("parameter"u8); - writer.WriteEndArray(); + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("parameterGroup"u8); - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ParameterGroup.Count > 0) { - writer.WriteStringValue(parameterGroupItem); - } + writer.WriteStartArray("parameterGroup"u8); - writer.WriteEndArray(); + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referencedElement"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ReferencedElement.Count > 0) { - writer.WriteStringValue(referencedElementItem); - } + writer.WriteStartArray("referencedElement"u8); - writer.WriteEndArray(); + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -400,70 +516,97 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - writer.WriteStartArray("containedElement"u8); - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ContainedElement.Count > 0) { - writer.WriteStringValue(containedElementItem); - } + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -471,43 +614,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); - writer.WriteStartArray("organizationalParticipant"u8); - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.OrganizationalParticipant.Count > 0) { - writer.WriteStringValue(organizationalParticipantItem); - } + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - writer.WriteStartArray("parameter"u8); - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.Parameter.Count > 0) { - writer.WriteStringValue(parameterItem); - } + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("parameterGroup"u8); - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ParameterGroup.Count > 0) { - writer.WriteStringValue(parameterGroupItem); - } + writer.WriteStartArray("parameterGroup"u8); - writer.WriteEndArray(); + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referencedElement"u8); - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + if (elementDefinition.ReferencedElement.Count > 0) { - writer.WriteStringValue(referencedElementItem); - } + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -561,17 +720,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -579,17 +737,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -615,17 +772,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("containedElement"u8); - - if(value is IEnumerable objectListContainedElement) + if (value is IEnumerable objectListContainedElement && objectListContainedElement.Any()) { + writer.WriteStartArray("containedElement"u8); + foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(containedElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definition": if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) @@ -633,17 +789,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -651,17 +806,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -669,17 +823,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -687,17 +840,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -759,17 +911,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("organizationalParticipant"u8); - - if(value is IEnumerable objectListOrganizationalParticipant) + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) { + writer.WriteStartArray("organizationalParticipant"u8); + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(organizationalParticipantItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "owner": if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) @@ -795,17 +946,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameter"u8); - - if(value is IEnumerable objectListParameter) + if (value is IEnumerable objectListParameter && objectListParameter.Any()) { + writer.WriteStartArray("parameter"u8); + foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "parametergroup": if(!AllowedVersionsPerProperty["parameterGroup"].Contains(requestedVersion)) @@ -813,17 +963,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterGroup"u8); - - if(value is IEnumerable objectListParameterGroup) + if (value is IEnumerable objectListParameterGroup && objectListParameterGroup.Any()) { + writer.WriteStartArray("parameterGroup"u8); + foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterGroupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "referencedelement": if(!AllowedVersionsPerProperty["referencedElement"].Contains(requestedVersion)) @@ -831,17 +980,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("referencedElement"u8); - - if(value is IEnumerable objectListReferencedElement) + if (value is IEnumerable objectListReferencedElement && objectListReferencedElement.Any()) { + writer.WriteStartArray("referencedElement"u8); + foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(referencedElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index b2751cf4f..db327a9bb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,54 +77,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -134,14 +154,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ParameterOverride.Count > 0) { - writer.WriteStringValue(parameterOverrideItem); - } + writer.WriteStartArray("parameterOverride"u8); - writer.WriteEndArray(); + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -150,72 +174,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); - writer.WriteEndArray(); + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -227,14 +279,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ParameterOverride.Count > 0) { - writer.WriteStringValue(parameterOverrideItem); - } + writer.WriteStartArray("parameterOverride"u8); - writer.WriteEndArray(); + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -243,72 +299,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -320,14 +404,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ParameterOverride.Count > 0) { - writer.WriteStringValue(parameterOverrideItem); - } + writer.WriteStartArray("parameterOverride"u8); - writer.WriteEndArray(); + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -349,72 +437,99 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludeOption"u8); - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ExcludeOption.Count > 0) { - writer.WriteStringValue(excludeOptionItem); - } + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -426,14 +541,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - writer.WriteStartArray("parameterOverride"u8); - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + if (elementUsage.ParameterOverride.Count > 0) { - writer.WriteStringValue(parameterOverrideItem); - } + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -487,17 +606,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -505,17 +623,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -541,17 +658,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "elementdefinition": if(!AllowedVersionsPerProperty["elementDefinition"].Contains(requestedVersion)) @@ -577,17 +693,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -595,17 +710,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeoption": if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) @@ -613,17 +727,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludeOption"u8); - - if(value is IEnumerable objectListExcludeOption) + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) { + writer.WriteStartArray("excludeOption"u8); + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludeOptionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -631,17 +744,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -739,17 +851,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterOverride"u8); - - if(value is IEnumerable objectListParameterOverride) + if (value is IEnumerable objectListParameterOverride && objectListParameterOverride.Any()) { + writer.WriteStartArray("parameterOverride"u8); + foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterOverrideItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index 917f19f7c..67c70cdf9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (emailAddress.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index 86eb793bd..3a8d69bcb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,23 +85,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -133,23 +141,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -194,23 +210,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -351,17 +375,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -369,17 +392,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index fc7c747ee..4c9432f1f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,32 +85,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -129,14 +141,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -151,32 +166,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -195,14 +222,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -230,32 +260,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -274,14 +316,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelDataNote.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -405,17 +450,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -423,17 +467,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -441,17 +484,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -531,17 +573,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 307e41233..f4376d3ba 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,123 +79,167 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.CommonFileStore.Count > 0) { - writer.WriteStringValue(commonFileStoreItem); - } + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.Iteration.Count > 0) { - writer.WriteStringValue(iterationItem); - } + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModel.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); - writer.WriteStartArray("book"u8); - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + if (engineeringModel.Book.Count > 0) { + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.CommonFileStore.Count > 0) { - writer.WriteStringValue(commonFileStoreItem); - } + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("genericNote"u8); - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.GenericNote.Count > 0) { - writer.WriteStringValue(genericNoteItem); - } + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.Iteration.Count > 0) { - writer.WriteStringValue(iterationItem); - } + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("modellingAnnotation"u8); - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ModellingAnnotation.Count > 0) { - writer.WriteStringValue(modellingAnnotationItem); - } + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -204,85 +248,117 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); - writer.WriteStartArray("book"u8); - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + if (engineeringModel.Book.Count > 0) { + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.CommonFileStore.Count > 0) { - writer.WriteStringValue(commonFileStoreItem); - } + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("genericNote"u8); - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.GenericNote.Count > 0) { - writer.WriteStringValue(genericNoteItem); - } + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.Iteration.Count > 0) { - writer.WriteStringValue(iterationItem); - } + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("modellingAnnotation"u8); - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ModellingAnnotation.Count > 0) { - writer.WriteStringValue(modellingAnnotationItem); - } + writer.WriteStartArray("modellingAnnotation"u8); - writer.WriteEndArray(); + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -304,85 +380,116 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + if (engineeringModel.Book.Count > 0) { + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - writer.WriteStartArray("commonFileStore"u8); - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.CommonFileStore.Count > 0) { - writer.WriteStringValue(commonFileStoreItem); - } + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("genericNote"u8); - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.GenericNote.Count > 0) { - writer.WriteStringValue(genericNoteItem); - } + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - writer.WriteStartArray("iteration"u8); - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.Iteration.Count > 0) { - writer.WriteStringValue(iterationItem); - } + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("modellingAnnotation"u8); - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + if (engineeringModel.ModellingAnnotation.Count > 0) { - writer.WriteStringValue(modellingAnnotationItem); - } + writer.WriteStartArray("modellingAnnotation"u8); - writer.WriteEndArray(); + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -436,17 +543,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("book"u8); - - if(value is IEnumerable objectListBook) + if (value is IEnumerable objectListBook && objectListBook.Any()) { + writer.WriteStartArray("book"u8); + foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(bookItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -472,17 +578,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("commonFileStore"u8); - - if(value is IEnumerable objectListCommonFileStore) + if (value is IEnumerable objectListCommonFileStore && objectListCommonFileStore.Any()) { + writer.WriteStartArray("commonFileStore"u8); + foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(commonFileStoreItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "engineeringmodelsetup": if(!AllowedVersionsPerProperty["engineeringModelSetup"].Contains(requestedVersion)) @@ -508,17 +613,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -526,17 +630,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "genericnote": if(!AllowedVersionsPerProperty["genericNote"].Contains(requestedVersion)) @@ -544,17 +647,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("genericNote"u8); - - if(value is IEnumerable objectListGenericNote) + if (value is IEnumerable objectListGenericNote && objectListGenericNote.Any()) { + writer.WriteStartArray("genericNote"u8); + foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(genericNoteItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -580,17 +682,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("iteration"u8); - - if(value is IEnumerable objectListIteration) + if (value is IEnumerable objectListIteration && objectListIteration.Any()) { + writer.WriteStartArray("iteration"u8); + foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(iterationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "lastmodifiedon": if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) @@ -616,17 +717,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("logEntry"u8); - - if(value is IEnumerable objectListLogEntry) + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) { + writer.WriteStartArray("logEntry"u8); + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(logEntryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modellingannotation": if(!AllowedVersionsPerProperty["modellingAnnotation"].Contains(requestedVersion)) @@ -634,17 +734,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("modellingAnnotation"u8); - - if(value is IEnumerable objectListModellingAnnotation) + if (value is IEnumerable objectListModellingAnnotation && objectListModellingAnnotation.Any()) { + writer.WriteStartArray("modellingAnnotation"u8); + foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(modellingAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index 7ee57ff94..49119c364 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,78 +77,106 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); - writer.WriteStartArray("activeDomain"u8); - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ActiveDomain.Count > 0) { - writer.WriteStringValue(activeDomainItem); - } + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.IterationSetup.Count > 0) { - writer.WriteStringValue(iterationSetupItem); - } + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("participant"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Participant.Count > 0) { - writer.WriteStringValue(participantItem); - } + writer.WriteStartArray("participant"u8); - writer.WriteEndArray(); + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requiredRdl"u8); - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.RequiredRdl.Count > 0) { - writer.WriteStringValue(requiredRdlItem); - } + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -170,74 +198,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); - writer.WriteStartArray("activeDomain"u8); - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ActiveDomain.Count > 0) { - writer.WriteStringValue(activeDomainItem); - } + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.IterationSetup.Count > 0) { - writer.WriteStringValue(iterationSetupItem); - } + writer.WriteStartArray("iterationSetup"u8); - writer.WriteEndArray(); + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -245,23 +301,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("participant"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Participant.Count > 0) { - writer.WriteStringValue(participantItem); - } + writer.WriteStartArray("participant"u8); - writer.WriteEndArray(); + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requiredRdl"u8); - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.RequiredRdl.Count > 0) { - writer.WriteStringValue(requiredRdlItem); - } + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -283,23 +347,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); - writer.WriteStartArray("activeDomain"u8); - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ActiveDomain.Count > 0) { - writer.WriteStringValue(activeDomainItem); - } + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); @@ -314,54 +386,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.IterationSetup.Count > 0) { - writer.WriteStringValue(iterationSetupItem); - } + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -369,32 +460,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("organizationalParticipant"u8); - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.OrganizationalParticipant.Count > 0) { - writer.WriteStringValue(organizationalParticipantItem); - } + writer.WriteStartArray("organizationalParticipant"u8); - writer.WriteEndArray(); + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participant"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Participant.Count > 0) { - writer.WriteStringValue(participantItem); - } + writer.WriteStartArray("participant"u8); - writer.WriteEndArray(); + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requiredRdl"u8); - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.RequiredRdl.Count > 0) { - writer.WriteStringValue(requiredRdlItem); - } + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -418,14 +521,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); - writer.WriteStartArray("activeDomain"u8); - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ActiveDomain.Count > 0) { - writer.WriteStringValue(activeDomainItem); - } + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("actor"u8); @@ -438,14 +545,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); @@ -460,54 +570,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - writer.WriteStartArray("iterationSetup"u8); - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.IterationSetup.Count > 0) { - writer.WriteStringValue(iterationSetupItem); - } + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -515,32 +644,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - writer.WriteStartArray("organizationalParticipant"u8); - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.OrganizationalParticipant.Count > 0) { - writer.WriteStringValue(organizationalParticipantItem); - } + writer.WriteStartArray("organizationalParticipant"u8); - writer.WriteEndArray(); + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participant"u8); - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.Participant.Count > 0) { - writer.WriteStringValue(participantItem); - } + writer.WriteStartArray("participant"u8); - writer.WriteEndArray(); + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requiredRdl"u8); - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + if (engineeringModelSetup.RequiredRdl.Count > 0) { - writer.WriteStringValue(requiredRdlItem); - } + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -589,17 +730,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("activeDomain"u8); - - if(value is IEnumerable objectListActiveDomain) + if (value is IEnumerable objectListActiveDomain && objectListActiveDomain.Any()) { + writer.WriteStartArray("activeDomain"u8); + foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(activeDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "actor": if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) @@ -625,17 +765,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -679,17 +818,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "engineeringmodeliid": if(!AllowedVersionsPerProperty["engineeringModelIid"].Contains(requestedVersion)) @@ -715,17 +853,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -733,17 +870,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -751,17 +887,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -787,17 +922,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("iterationSetup"u8); - - if(value is IEnumerable objectListIterationSetup) + if (value is IEnumerable objectListIterationSetup && objectListIterationSetup.Any()) { + writer.WriteStartArray("iterationSetup"u8); + foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(iterationSetupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "kind": if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) @@ -859,17 +993,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("organizationalParticipant"u8); - - if(value is IEnumerable objectListOrganizationalParticipant) + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) { + writer.WriteStartArray("organizationalParticipant"u8); + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(organizationalParticipantItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "participant": if(!AllowedVersionsPerProperty["participant"].Contains(requestedVersion)) @@ -877,17 +1010,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("participant"u8); - - if(value is IEnumerable objectListParticipant) + if (value is IEnumerable objectListParticipant && objectListParticipant.Any()) { + writer.WriteStartArray("participant"u8); + foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(participantItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "requiredrdl": if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) @@ -895,17 +1027,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("requiredRdl"u8); - - if(value is IEnumerable objectListRequiredRdl) + if (value is IEnumerable objectListRequiredRdl && objectListRequiredRdl.Any()) { + writer.WriteStartArray("requiredRdl"u8); + foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(requiredRdlItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 64c281224..e89498ed5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -129,75 +145,103 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.ShortName); writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + if (enumerationParameterType.ValueDefinition.Count > 0) { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -213,75 +257,103 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.ShortName); writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + if (enumerationParameterType.ValueDefinition.Count > 0) { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -299,14 +371,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + if (enumerationParameterType.ValueDefinition.Count > 0) { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -322,63 +398,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -396,14 +495,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + if (enumerationParameterType.ValueDefinition.Count > 0) { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -451,17 +554,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "allowmultiselect": if(!AllowedVersionsPerProperty["allowMultiSelect"].Contains(requestedVersion)) @@ -487,17 +589,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -523,17 +624,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -541,17 +641,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -559,17 +658,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -577,17 +675,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -739,17 +836,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index ccb846988..935d060a1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -117,52 +129,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -177,52 +209,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -250,52 +302,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (enumerationValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -355,17 +426,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -391,17 +461,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -409,17 +478,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -427,17 +495,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -445,17 +512,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index 7efaec894..fad0793c8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -83,37 +83,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -121,37 +133,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -159,14 +183,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); @@ -186,23 +214,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -210,14 +246,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (exclusiveOrExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); @@ -285,17 +325,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -303,17 +342,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -375,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("term"u8); - - if(value is IEnumerable objectListTerm) + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { + writer.WriteStartArray("term"u8); + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(termItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 111625268..51c1a7546 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,14 +79,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.Correspondence.Count > 0) { - writer.WriteStringValue(correspondenceItem); - } + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("externalFormat"u8); @@ -118,32 +122,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.Correspondence.Count > 0) { - writer.WriteStringValue(correspondenceItem); - } + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("externalFormat"u8); @@ -177,32 +193,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.Correspondence.Count > 0) { - writer.WriteStringValue(correspondenceItem); - } + writer.WriteStartArray("correspondence"u8); - writer.WriteEndArray(); + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("externalFormat"u8); @@ -249,32 +277,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - writer.WriteStartArray("correspondence"u8); - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.Correspondence.Count > 0) { - writer.WriteStringValue(correspondenceItem); - } + writer.WriteStartArray("correspondence"u8); - writer.WriteEndArray(); + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (externalIdentifierMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("externalFormat"u8); @@ -369,17 +409,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("correspondence"u8); - - if(value is IEnumerable objectListCorrespondence) + if (value is IEnumerable objectListCorrespondence && objectListCorrespondence.Any()) { + writer.WriteStartArray("correspondence"u8); + foreach(var correspondenceItem in objectListCorrespondence.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(correspondenceItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -387,17 +426,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -405,17 +443,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "externalformat": if(!AllowedVersionsPerProperty["externalFormat"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 3685cd366..511f72b51 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -96,14 +96,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + if (fileRevision.FileType.Count > 0) { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -133,32 +137,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + if (fileRevision.FileType.Count > 0) { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -190,32 +206,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + if (fileRevision.FileType.Count > 0) { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -260,32 +288,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileRevision.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + if (fileRevision.FileType.Count > 0) { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -433,17 +473,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -451,17 +490,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "filetype": if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) @@ -469,17 +507,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("fileType"u8); - - if(value is IEnumerable objectListFileType) + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { + writer.WriteStartArray("fileType"u8); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(fileTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 0de93fab2..7cd4bbe62 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + if (file.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - writer.WriteStartArray("fileRevision"u8); - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + if (file.FileRevision.Count > 0) { - writer.WriteStringValue(fileRevisionItem); - } + writer.WriteStartArray("fileRevision"u8); - writer.WriteEndArray(); + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -117,43 +125,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + if (file.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileRevision"u8); - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + if (file.FileRevision.Count > 0) { - writer.WriteStringValue(fileRevisionItem); - } + writer.WriteStartArray("fileRevision"u8); - writer.WriteEndArray(); + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -177,43 +201,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + if (file.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileRevision"u8); - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + if (file.FileRevision.Count > 0) { - writer.WriteStringValue(fileRevisionItem); - } + writer.WriteStartArray("fileRevision"u8); - writer.WriteEndArray(); + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -250,43 +290,58 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + if (file.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (file.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileRevision"u8); - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + if (file.FileRevision.Count > 0) { - writer.WriteStringValue(fileRevisionItem); - } + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -355,17 +410,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -391,17 +445,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -409,17 +462,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "filerevision": if(!AllowedVersionsPerProperty["fileRevision"].Contains(requestedVersion)) @@ -427,17 +479,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("fileRevision"u8); - - if(value is IEnumerable objectListFileRevision) + if (value is IEnumerable objectListFileRevision && objectListFileRevision.Any()) { + writer.WriteStartArray("fileRevision"u8); + foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(fileRevisionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index abb0ef315..8a016389b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + if (fileType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + if (fileType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + if (fileType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (fileType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -130,63 +146,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + if (fileType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + if (fileType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + if (fileType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (fileType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -203,63 +243,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + if (fileType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + if (fileType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + if (fileType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (fileType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -289,63 +353,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + if (fileType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + if (fileType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + if (fileType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (fileType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (fileType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "extension": if(!AllowedVersionsPerProperty["extension"].Contains(requestedVersion)) @@ -533,17 +615,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 084799a73..ec77511fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -122,23 +122,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -170,23 +178,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -231,23 +247,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (folder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -379,17 +403,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -397,17 +420,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index 8574105e2..f7c3b038f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + if (glossary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + if (glossary.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + if (glossary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (glossary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -125,73 +141,101 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + if (glossary.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + if (glossary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + if (glossary.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + if (glossary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (glossary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -205,73 +249,101 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + if (glossary.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + if (glossary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + if (glossary.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + if (glossary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (glossary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -285,14 +357,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + if (glossary.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); @@ -310,61 +386,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + if (glossary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + if (glossary.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + if (glossary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (glossary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (glossary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -378,14 +477,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - writer.WriteStartArray("term"u8); - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + if (glossary.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); @@ -435,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -453,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -489,17 +590,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -507,17 +607,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -525,17 +624,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -543,17 +641,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -669,17 +766,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("term"u8); - - if(value is IEnumerable objectListTerm) + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { + writer.WriteStartArray("term"u8); + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(termItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 0fa9e943c..7d3d8eb46 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,61 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + if (goal.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + if (goal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + if (goal.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (goal.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -146,61 +170,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + if (goal.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + if (goal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + if (goal.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (goal.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -228,61 +276,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + if (goal.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + if (goal.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + if (goal.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (goal.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (goal.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -342,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -360,17 +430,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -396,17 +465,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -414,17 +482,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -432,17 +499,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -450,17 +516,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index d8d7d1034..e78ce8d2c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -96,23 +96,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -131,23 +139,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -179,23 +195,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (hyperLink.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -291,17 +315,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -309,17 +332,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index 2c602e0b1..d535f6fe2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (idCorrespondence.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "externalid": if(!AllowedVersionsPerProperty["externalId"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index 0ba05cad9..1162a381a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); @@ -134,23 +142,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); @@ -237,17 +253,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -255,17 +270,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 6fa8d528c..e2e465e24 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -141,64 +157,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -208,14 +248,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -237,64 +281,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -304,14 +372,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -335,14 +407,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -358,52 +434,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -413,14 +508,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -444,14 +543,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (intervalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -499,17 +602,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -535,17 +637,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -553,17 +654,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -571,17 +671,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -589,17 +688,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -679,17 +777,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("mappingToReferenceScale"u8); - - if(value is IEnumerable objectListMappingToReferenceScale) + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { + writer.WriteStartArray("mappingToReferenceScale"u8); + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(mappingToReferenceScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "maximumpermissiblevalue": if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) @@ -895,17 +992,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index 09ac4f3a3..6dea82aa3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); - writer.WriteStartArray("actualFiniteStateList"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.ActualFiniteStateList.Count > 0) { - writer.WriteStringValue(actualFiniteStateListItem); - } + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -99,92 +103,127 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("domainFileStore"u8); - - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if (iteration.DomainFileStore.Count > 0) { - writer.WriteStringValue(domainFileStoreItem); - } + writer.WriteStartArray("domainFileStore"u8); - writer.WriteEndArray(); + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("element"u8); - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + if (iteration.Element.Count > 0) { - writer.WriteStringValue(elementItem); - } + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("externalIdentifierMap"u8); - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExternalIdentifierMap.Count > 0) { - writer.WriteStringValue(externalIdentifierMapItem); - } + writer.WriteStartArray("externalIdentifierMap"u8); - writer.WriteEndArray(); + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); writer.WritePropertyName("iterationSetup"u8); writer.WriteStringValue(iteration.IterationSetup); - writer.WriteStartArray("option"u8); - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + if (iteration.Option.Count > 0) { + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.PossibleFiniteStateList.Count > 0) { - writer.WriteStringValue(possibleFiniteStateListItem); - } + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("publication"u8); - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + if (iteration.Publication.Count > 0) { - writer.WriteStringValue(publicationItem); - } + writer.WriteStartArray("publication"u8); - writer.WriteEndArray(); + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("relationship"u8); - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + if (iteration.Relationship.Count > 0) { - writer.WriteStringValue(relationshipItem); - } + writer.WriteStartArray("relationship"u8); - writer.WriteEndArray(); + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requirementsSpecification"u8); - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + if (iteration.RequirementsSpecification.Count > 0) { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + if (iteration.RuleVerificationList.Count > 0) { - writer.WriteStringValue(ruleVerificationListItem); - } + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("sourceIterationIid"u8); @@ -211,14 +250,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); - writer.WriteStartArray("actualFiniteStateList"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.ActualFiniteStateList.Count > 0) { - writer.WriteStringValue(actualFiniteStateListItem); - } + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -233,68 +276,95 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramCanvas"u8); - - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + if (iteration.DiagramCanvas.Count > 0) { - writer.WriteStringValue(diagramCanvasItem); - } + writer.WriteStartArray("diagramCanvas"u8); - writer.WriteEndArray(); + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainFileStore"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if (iteration.DomainFileStore.Count > 0) { - writer.WriteStringValue(domainFileStoreItem); - } + writer.WriteStartArray("domainFileStore"u8); - writer.WriteEndArray(); + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("element"u8); - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + if (iteration.Element.Count > 0) { - writer.WriteStringValue(elementItem); - } + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("externalIdentifierMap"u8); - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExternalIdentifierMap.Count > 0) { - writer.WriteStringValue(externalIdentifierMapItem); - } + writer.WriteStartArray("externalIdentifierMap"u8); - writer.WriteEndArray(); + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + if (iteration.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); - writer.WriteEndArray(); + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -302,70 +372,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + if (iteration.Option.Count > 0) { + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.PossibleFiniteStateList.Count > 0) { - writer.WriteStringValue(possibleFiniteStateListItem); - } + writer.WriteStartArray("possibleFiniteStateList"u8); - writer.WriteEndArray(); + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("publication"u8); - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + if (iteration.Publication.Count > 0) { - writer.WriteStringValue(publicationItem); - } + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relationship"u8); - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + if (iteration.Relationship.Count > 0) { - writer.WriteStringValue(relationshipItem); - } + writer.WriteStartArray("relationship"u8); - writer.WriteEndArray(); + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requirementsSpecification"u8); - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + if (iteration.RequirementsSpecification.Count > 0) { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteStartArray("requirementsSpecification"u8); - writer.WriteEndArray(); + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + if (iteration.RuleVerificationList.Count > 0) { - writer.WriteStringValue(ruleVerificationListItem); - } + writer.WriteStartArray("ruleVerificationList"u8); - writer.WriteEndArray(); + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("sharedDiagramStyle"u8); - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + if (iteration.SharedDiagramStyle.Count > 0) { - writer.WriteStringValue(sharedDiagramStyleItem); - } + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("sourceIterationIid"u8); @@ -378,32 +476,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + if (iteration.Stakeholder.Count > 0) { - writer.WriteStringValue(stakeholderItem); - } + writer.WriteStartArray("stakeholder"u8); - writer.WriteEndArray(); + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValueMap"u8); - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValueMap.Count > 0) { - writer.WriteStringValue(stakeholderValueMapItem); - } + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("topElement"u8); @@ -416,26 +525,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (iteration.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); - writer.WriteStartArray("actualFiniteStateList"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.ActualFiniteStateList.Count > 0) { - writer.WriteStringValue(actualFiniteStateListItem); - } + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -450,68 +566,95 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramCanvas"u8); - - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + if (iteration.DiagramCanvas.Count > 0) { - writer.WriteStringValue(diagramCanvasItem); - } + writer.WriteStartArray("diagramCanvas"u8); - writer.WriteEndArray(); + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainFileStore"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if (iteration.DomainFileStore.Count > 0) { - writer.WriteStringValue(domainFileStoreItem); - } + writer.WriteStartArray("domainFileStore"u8); - writer.WriteEndArray(); + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("element"u8); - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + if (iteration.Element.Count > 0) { - writer.WriteStringValue(elementItem); - } + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("externalIdentifierMap"u8); - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExternalIdentifierMap.Count > 0) { - writer.WriteStringValue(externalIdentifierMapItem); - } + writer.WriteStartArray("externalIdentifierMap"u8); - writer.WriteEndArray(); + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + if (iteration.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); - writer.WriteEndArray(); + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -519,70 +662,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + if (iteration.Option.Count > 0) { + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.PossibleFiniteStateList.Count > 0) { - writer.WriteStringValue(possibleFiniteStateListItem); - } + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("publication"u8); - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + if (iteration.Publication.Count > 0) { - writer.WriteStringValue(publicationItem); - } + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relationship"u8); - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + if (iteration.Relationship.Count > 0) { - writer.WriteStringValue(relationshipItem); - } + writer.WriteStartArray("relationship"u8); - writer.WriteEndArray(); + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requirementsSpecification"u8); - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + if (iteration.RequirementsSpecification.Count > 0) { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + if (iteration.RuleVerificationList.Count > 0) { - writer.WriteStringValue(ruleVerificationListItem); - } + writer.WriteStartArray("ruleVerificationList"u8); - writer.WriteEndArray(); + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("sharedDiagramStyle"u8); - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + if (iteration.SharedDiagramStyle.Count > 0) { - writer.WriteStringValue(sharedDiagramStyleItem); - } + writer.WriteStartArray("sharedDiagramStyle"u8); - writer.WriteEndArray(); + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("sourceIterationIid"u8); @@ -595,32 +766,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + if (iteration.Stakeholder.Count > 0) { - writer.WriteStringValue(stakeholderItem); - } + writer.WriteStartArray("stakeholder"u8); - writer.WriteEndArray(); + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValueMap"u8); - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValueMap.Count > 0) { - writer.WriteStringValue(stakeholderValueMapItem); - } + writer.WriteStartArray("stakeholderValueMap"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); @@ -635,14 +817,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (iteration.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); - writer.WriteEndArray(); + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -658,14 +843,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("actualFiniteStateList"u8); - - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.ActualFiniteStateList.Count > 0) { - writer.WriteStringValue(actualFiniteStateListItem); - } + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -680,68 +868,95 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("diagramCanvas"u8); - - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + if (iteration.DiagramCanvas.Count > 0) { - writer.WriteStringValue(diagramCanvasItem); - } + writer.WriteStartArray("diagramCanvas"u8); - writer.WriteEndArray(); + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainFileStore"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + if (iteration.DomainFileStore.Count > 0) { - writer.WriteStringValue(domainFileStoreItem); - } + writer.WriteStartArray("domainFileStore"u8); - writer.WriteEndArray(); + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("element"u8); - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + if (iteration.Element.Count > 0) { - writer.WriteStringValue(elementItem); - } + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("externalIdentifierMap"u8); - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.ExternalIdentifierMap.Count > 0) { - writer.WriteStringValue(externalIdentifierMapItem); - } + writer.WriteStartArray("externalIdentifierMap"u8); - writer.WriteEndArray(); + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + if (iteration.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); - writer.WriteEndArray(); + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -749,70 +964,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("option"u8); - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + if (iteration.Option.Count > 0) { + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("possibleFiniteStateList"u8); - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + if (iteration.PossibleFiniteStateList.Count > 0) { - writer.WriteStringValue(possibleFiniteStateListItem); - } + writer.WriteStartArray("possibleFiniteStateList"u8); - writer.WriteEndArray(); + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("publication"u8); - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + if (iteration.Publication.Count > 0) { - writer.WriteStringValue(publicationItem); - } + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relationship"u8); - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + if (iteration.Relationship.Count > 0) { - writer.WriteStringValue(relationshipItem); - } + writer.WriteStartArray("relationship"u8); - writer.WriteEndArray(); + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("requirementsSpecification"u8); - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + if (iteration.RequirementsSpecification.Count > 0) { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteStartArray("requirementsSpecification"u8); - writer.WriteEndArray(); + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - writer.WriteStartArray("ruleVerificationList"u8); - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + if (iteration.RuleVerificationList.Count > 0) { - writer.WriteStringValue(ruleVerificationListItem); - } + writer.WriteStartArray("ruleVerificationList"u8); - writer.WriteEndArray(); + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("sharedDiagramStyle"u8); - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + if (iteration.SharedDiagramStyle.Count > 0) { - writer.WriteStringValue(sharedDiagramStyleItem); - } + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("sourceIterationIid"u8); @@ -825,32 +1068,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("stakeholder"u8); - - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + if (iteration.Stakeholder.Count > 0) { - writer.WriteStringValue(stakeholderItem); - } + writer.WriteStartArray("stakeholder"u8); - writer.WriteEndArray(); + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("stakeholderValueMap"u8); - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + if (iteration.StakeholderValueMap.Count > 0) { - writer.WriteStringValue(stakeholderValueMapItem); - } + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); @@ -865,14 +1119,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (iteration.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -920,17 +1177,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("actualFiniteStateList"u8); - - if(value is IEnumerable objectListActualFiniteStateList) + if (value is IEnumerable objectListActualFiniteStateList && objectListActualFiniteStateList.Any()) { + writer.WriteStartArray("actualFiniteStateList"u8); + foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(actualFiniteStateListItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -974,17 +1230,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("diagramCanvas"u8); - - if(value is IEnumerable objectListDiagramCanvas) + if (value is IEnumerable objectListDiagramCanvas && objectListDiagramCanvas.Any()) { + writer.WriteStartArray("diagramCanvas"u8); + foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(diagramCanvasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "domainfilestore": if(!AllowedVersionsPerProperty["domainFileStore"].Contains(requestedVersion)) @@ -992,17 +1247,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domainFileStore"u8); - - if(value is IEnumerable objectListDomainFileStore) + if (value is IEnumerable objectListDomainFileStore && objectListDomainFileStore.Any()) { + writer.WriteStartArray("domainFileStore"u8); + foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainFileStoreItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "element": if(!AllowedVersionsPerProperty["element"].Contains(requestedVersion)) @@ -1010,17 +1264,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("element"u8); - - if(value is IEnumerable objectListElement) + if (value is IEnumerable objectListElement && objectListElement.Any()) { + writer.WriteStartArray("element"u8); + foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(elementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -1028,17 +1281,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -1046,17 +1298,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "externalidentifiermap": if(!AllowedVersionsPerProperty["externalIdentifierMap"].Contains(requestedVersion)) @@ -1064,17 +1315,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("externalIdentifierMap"u8); - - if(value is IEnumerable objectListExternalIdentifierMap) + if (value is IEnumerable objectListExternalIdentifierMap && objectListExternalIdentifierMap.Any()) { + writer.WriteStartArray("externalIdentifierMap"u8); + foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(externalIdentifierMapItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "goal": if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) @@ -1082,17 +1332,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("goal"u8); - - if(value is IEnumerable objectListGoal) + if (value is IEnumerable objectListGoal && objectListGoal.Any()) { + writer.WriteStartArray("goal"u8); + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(goalItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -1154,17 +1403,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("option"u8); - - if(value is IEnumerable objectListOption) + if (value is IEnumerable objectListOption && objectListOption.Any()) { + writer.WriteStartArray("option"u8); + foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(optionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "possiblefinitestatelist": if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) @@ -1172,17 +1420,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleFiniteStateList"u8); - - if(value is IEnumerable objectListPossibleFiniteStateList) + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) { + writer.WriteStartArray("possibleFiniteStateList"u8); + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(possibleFiniteStateListItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "publication": if(!AllowedVersionsPerProperty["publication"].Contains(requestedVersion)) @@ -1190,17 +1437,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("publication"u8); - - if(value is IEnumerable objectListPublication) + if (value is IEnumerable objectListPublication && objectListPublication.Any()) { + writer.WriteStartArray("publication"u8); + foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(publicationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "relationship": if(!AllowedVersionsPerProperty["relationship"].Contains(requestedVersion)) @@ -1208,17 +1454,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relationship"u8); - - if(value is IEnumerable objectListRelationship) + if (value is IEnumerable objectListRelationship && objectListRelationship.Any()) { + writer.WriteStartArray("relationship"u8); + foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relationshipItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "requirementsspecification": if(!AllowedVersionsPerProperty["requirementsSpecification"].Contains(requestedVersion)) @@ -1226,17 +1471,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("requirementsSpecification"u8); - - if(value is IEnumerable objectListRequirementsSpecification) + if (value is IEnumerable objectListRequirementsSpecification && objectListRequirementsSpecification.Any()) { + writer.WriteStartArray("requirementsSpecification"u8); + foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(requirementsSpecificationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -1262,17 +1506,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("ruleVerificationList"u8); - - if(value is IEnumerable objectListRuleVerificationList) + if (value is IEnumerable objectListRuleVerificationList && objectListRuleVerificationList.Any()) { + writer.WriteStartArray("ruleVerificationList"u8); + foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(ruleVerificationListItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shareddiagramstyle": if(!AllowedVersionsPerProperty["sharedDiagramStyle"].Contains(requestedVersion)) @@ -1280,17 +1523,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sharedDiagramStyle"u8); - - if(value is IEnumerable objectListSharedDiagramStyle) + if (value is IEnumerable objectListSharedDiagramStyle && objectListSharedDiagramStyle.Any()) { + writer.WriteStartArray("sharedDiagramStyle"u8); + foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sharedDiagramStyleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "sourceiterationiid": if(!AllowedVersionsPerProperty["sourceIterationIid"].Contains(requestedVersion)) @@ -1316,17 +1558,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("stakeholder"u8); - - if(value is IEnumerable objectListStakeholder) + if (value is IEnumerable objectListStakeholder && objectListStakeholder.Any()) { + writer.WriteStartArray("stakeholder"u8); + foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(stakeholderItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "stakeholdervalue": if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) @@ -1334,17 +1575,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("stakeholderValue"u8); - - if(value is IEnumerable objectListStakeholderValue) + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { + writer.WriteStartArray("stakeholderValue"u8); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(stakeholderValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "stakeholdervaluemap": if(!AllowedVersionsPerProperty["stakeholderValueMap"].Contains(requestedVersion)) @@ -1352,17 +1592,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("stakeholderValueMap"u8); - - if(value is IEnumerable objectListStakeholderValueMap) + if (value is IEnumerable objectListStakeholderValueMap && objectListStakeholderValueMap.Any()) { + writer.WriteStartArray("stakeholderValueMap"u8); + foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(stakeholderValueMapItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) @@ -1406,17 +1645,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueGroup"u8); - - if(value is IEnumerable objectListValueGroup) + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) { + writer.WriteStartArray("valueGroup"u8); + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueGroupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index ade206847..d8b482f28 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -124,23 +124,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("frozenOn"u8); @@ -185,23 +193,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("frozenOn"u8); @@ -259,23 +275,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (iterationSetup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("frozenOn"u8); @@ -413,17 +437,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -431,17 +454,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "frozenon": if(!AllowedVersionsPerProperty["frozenOn"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 6a462edc1..5321fc899 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -123,54 +135,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -189,54 +221,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -268,54 +320,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (linearConversionUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -379,17 +450,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -433,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -451,17 +520,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -469,17 +537,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -487,17 +554,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index b6919f1eb..60bad268c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,14 +79,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.2.0"); writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - writer.WriteStartArray("affectedReferenceIid"u8); - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) { - writer.WriteStringValue(affectedReferenceIidItem); - } + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -94,23 +98,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (logEntryChangelogItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (logEntryChangelogItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -136,14 +148,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - writer.WriteStartArray("affectedReferenceIid"u8); - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) { - writer.WriteStringValue(affectedReferenceIidItem); - } + writer.WriteStartArray("affectedReferenceIid"u8); - writer.WriteEndArray(); + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -151,23 +167,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (logEntryChangelogItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (logEntryChangelogItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -241,17 +265,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("affectedReferenceIid"u8); - - if(value is IEnumerable objectListAffectedReferenceIid) + if (value is IEnumerable objectListAffectedReferenceIid && objectListAffectedReferenceIid.Any()) { - foreach(var affectedReferenceIidItem in objectListAffectedReferenceIid) + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach (var affectedReferenceIidItem in objectListAffectedReferenceIid) { writer.WriteStringValue((Guid)affectedReferenceIidItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "changedescription": if(!AllowedVersionsPerProperty["changeDescription"].Contains(requestedVersion)) @@ -313,17 +336,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -331,17 +353,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index 04e2d9987..d3322fe65 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,38 +77,50 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -120,14 +132,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -143,14 +159,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ReferenceQuantityValue.Count > 0) { - writer.WriteStringValue(referenceQuantityValueItem); - } + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -158,68 +178,92 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -231,14 +275,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -256,14 +304,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ReferenceQuantityValue.Count > 0) { - writer.WriteStringValue(referenceQuantityValueItem); - } + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -271,68 +323,92 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -344,14 +420,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -369,14 +449,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ReferenceQuantityValue.Count > 0) { - writer.WriteStringValue(referenceQuantityValueItem); - } + writer.WriteStartArray("referenceQuantityValue"u8); - writer.WriteEndArray(); + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -386,14 +470,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -409,56 +497,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -470,14 +577,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -495,14 +606,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - writer.WriteStartArray("referenceQuantityValue"u8); - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ReferenceQuantityValue.Count > 0) { - writer.WriteStringValue(referenceQuantityValueItem); - } + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -512,14 +627,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (logarithmicScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -567,17 +686,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -603,17 +721,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -621,17 +738,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -639,17 +755,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "exponent": if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) @@ -693,17 +808,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -801,17 +915,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("mappingToReferenceScale"u8); - - if(value is IEnumerable objectListMappingToReferenceScale) + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { + writer.WriteStartArray("mappingToReferenceScale"u8); + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(mappingToReferenceScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "maximumpermissiblevalue": if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) @@ -963,17 +1076,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("referenceQuantityValue"u8); - - if(value is IEnumerable objectListReferenceQuantityValue) + if (value is IEnumerable objectListReferenceQuantityValue && objectListReferenceQuantityValue.Any()) { + writer.WriteStartArray("referenceQuantityValue"u8); + foreach(var referenceQuantityValueItem in objectListReferenceQuantityValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(referenceQuantityValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -1053,17 +1165,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the LogarithmicScale"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index 4514063da..cab5d52c2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -94,23 +94,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -127,23 +135,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -173,23 +189,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (mappingToReferenceScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -283,17 +307,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -301,17 +324,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index e2775bf9a..fc36aa12d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,23 +77,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + if (modelLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + if (modelLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -106,14 +114,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -132,23 +143,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + if (modelLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + if (modelLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -161,14 +180,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -176,23 +198,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -207,23 +237,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + if (modelLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + if (modelLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); - writer.WriteEndArray(); + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -236,14 +274,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -251,23 +292,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -275,14 +324,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.LogEntryChangelogItem.Count > 0) { - writer.WriteStringValue(logEntryChangelogItemItem); - } + writer.WriteStartArray("logEntryChangelogItem"u8); - writer.WriteEndArray(); + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -304,23 +357,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + if (modelLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + if (modelLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); - writer.WriteEndArray(); + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -333,14 +393,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -348,23 +411,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -372,14 +443,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + if (modelLogEntry.LogEntryChangelogItem.Count > 0) { - writer.WriteStringValue(logEntryChangelogItemItem); - } + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -433,17 +508,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("affectedDomainIid"u8); - - if(value is IEnumerable objectListAffectedDomainIid) + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) { - foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + writer.WriteStartArray("affectedDomainIid"u8); + + foreach (var affectedDomainIidItem in objectListAffectedDomainIid) { writer.WriteStringValue((Guid)affectedDomainIidItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "affecteditemiid": if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) @@ -451,17 +525,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("affectedItemIid"u8); - - if(value is IEnumerable objectListAffectedItemIid) + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) { - foreach(var affectedItemIidItem in objectListAffectedItemIid) + writer.WriteStartArray("affectedItemIid"u8); + + foreach (var affectedItemIidItem in objectListAffectedItemIid) { writer.WriteStringValue((Guid)affectedItemIidItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -487,17 +560,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -559,17 +631,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -577,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -649,17 +719,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("logEntryChangelogItem"u8); - - if(value is IEnumerable objectListLogEntryChangelogItem) + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) { + writer.WriteStartArray("logEntryChangelogItem"u8); + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(logEntryChangelogItemItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index eb5656fcc..da237cf29 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,110 +77,154 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); - writer.WriteEndArray(); + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -195,147 +239,207 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); - writer.WriteEndArray(); + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); - writer.WriteEndArray(); + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -343,23 +447,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); - writer.WriteEndArray(); + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -374,147 +486,207 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); - writer.WriteEndArray(); + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); - writer.WriteEndArray(); + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); - writer.WriteEndArray(); + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); - writer.WriteEndArray(); + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); - writer.WriteEndArray(); + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -522,23 +694,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -553,45 +733,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -607,106 +803,149 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); - writer.WriteEndArray(); + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -714,23 +953,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -745,45 +992,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); - writer.WriteEndArray(); + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); - writer.WriteEndArray(); + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (modelReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; default: @@ -831,17 +1094,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "basequantitykind": if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) @@ -849,17 +1111,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("baseQuantityKind"u8); - - if(value is IEnumerable objectListBaseQuantityKind) + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) { + writer.WriteStartArray("baseQuantityKind"u8); + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(baseQuantityKindItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "baseunit": if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) @@ -867,17 +1128,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("baseUnit"u8); - - if(value is IEnumerable objectListBaseUnit) + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) { + writer.WriteStartArray("baseUnit"u8); + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(baseUnitItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -903,17 +1163,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("constant"u8); - - if(value is IEnumerable objectListConstant) + if (value is IEnumerable objectListConstant && objectListConstant.Any()) { + writer.WriteStartArray("constant"u8); + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(constantItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definedcategory": if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) @@ -921,17 +1180,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definedCategory"u8); - - if(value is IEnumerable objectListDefinedCategory) + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) { + writer.WriteStartArray("definedCategory"u8); + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definedCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definition": if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) @@ -939,17 +1197,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -957,17 +1214,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -975,17 +1231,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "filetype": if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) @@ -993,17 +1248,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("fileType"u8); - - if(value is IEnumerable objectListFileType) + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { + writer.WriteStartArray("fileType"u8); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(fileTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "glossary": if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) @@ -1011,17 +1265,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("glossary"u8); - - if(value is IEnumerable objectListGlossary) + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) { + writer.WriteStartArray("glossary"u8); + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(glossaryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -1029,17 +1282,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -1101,17 +1353,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterType"u8); - - if(value is IEnumerable objectListParameterType) + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { + writer.WriteStartArray("parameterType"u8); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "referencesource": if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) @@ -1119,17 +1370,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("referenceSource"u8); - - if(value is IEnumerable objectListReferenceSource) + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) { + writer.WriteStartArray("referenceSource"u8); + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(referenceSourceItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "requiredrdl": if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) @@ -1173,17 +1423,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("rule"u8); - - if(value is IEnumerable objectListRule) + if (value is IEnumerable objectListRule && objectListRule.Any()) { + writer.WriteStartArray("rule"u8); + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(ruleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "scale": if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) @@ -1191,17 +1440,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("scale"u8); - - if(value is IEnumerable objectListScale) + if (value is IEnumerable objectListScale && objectListScale.Any()) { + writer.WriteStartArray("scale"u8); + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(scaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shortname": if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) @@ -1245,17 +1493,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("unit"u8); - - if(value is IEnumerable objectListUnit) + if (value is IEnumerable objectListUnit && objectListUnit.Any()) { + writer.WriteStartArray("unit"u8); + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(unitItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "unitprefix": if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) @@ -1263,17 +1510,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("unitPrefix"u8); - - if(value is IEnumerable objectListUnitPrefix) + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) { + writer.WriteStartArray("unitPrefix"u8); + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(unitPrefixItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index f2c660d07..84ba9f986 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -112,23 +120,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -158,23 +174,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (modellingThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -252,17 +276,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -270,17 +293,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index b16ada893..c02a2a1fb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -116,14 +128,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(multiRelationshipRule.MinRelated); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.RelatedCategory.Count > 0) { - writer.WriteStringValue(relatedCategoryItem); - } + writer.WriteStartArray("relatedCategory"u8); - writer.WriteEndArray(); + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -134,52 +150,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -193,14 +229,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.RelatedCategory.Count > 0) { - writer.WriteStringValue(relatedCategoryItem); - } + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -211,52 +251,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -270,14 +330,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.RelatedCategory.Count > 0) { - writer.WriteStringValue(relatedCategoryItem); - } + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -301,52 +365,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -360,14 +443,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - writer.WriteStartArray("relatedCategory"u8); - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + if (multiRelationshipRule.RelatedCategory.Count > 0) { - writer.WriteStringValue(relatedCategoryItem); - } + writer.WriteStartArray("relatedCategory"u8); - writer.WriteEndArray(); + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -423,17 +510,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -459,17 +545,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -477,17 +562,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -495,17 +579,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -513,17 +596,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -639,17 +721,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedCategory"u8); - - if(value is IEnumerable objectListRelatedCategory) + if (value is IEnumerable objectListRelatedCategory && objectListRelatedCategory.Any()) { + writer.WriteStartArray("relatedCategory"u8); + foreach(var relatedCategoryItem in objectListRelatedCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "relationshipcategory": if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index a32f0b238..6090ab3ed 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); @@ -92,48 +96,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Iid); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -141,57 +161,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -201,23 +241,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -237,34 +285,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -274,23 +333,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (multiRelationship.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -342,17 +409,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -378,17 +444,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -396,17 +461,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -486,17 +550,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterValue"u8); - - if(value is IEnumerable objectListParameterValue) + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { + writer.WriteStartArray("parameterValue"u8); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "relatedthing": if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) @@ -504,17 +567,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index f609812ee..27770f1f8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -94,23 +94,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -129,23 +137,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -177,23 +193,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (naturalLanguage.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -273,17 +297,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -291,17 +314,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index ec17d25b0..b734ebda2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,27 +79,35 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + if (nestedElement.ElementUsage.Count > 0) { + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); writer.WritePropertyName("isVolatile"u8); writer.WriteBooleanValue(nestedElement.IsVolatile); - writer.WriteStartArray("nestedParameter"u8); - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.NestedParameter.Count > 0) { - writer.WriteStringValue(nestedParameterItem); - } + writer.WriteStartArray("nestedParameter"u8); - writer.WriteEndArray(); + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -110,32 +118,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + if (nestedElement.ElementUsage.Count > 0) { + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -143,14 +163,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.NestedParameter.Count > 0) { - writer.WriteStringValue(nestedParameterItem); - } + writer.WriteStartArray("nestedParameter"u8); - writer.WriteEndArray(); + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -161,32 +185,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + if (nestedElement.ElementUsage.Count > 0) { + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -194,14 +230,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.NestedParameter.Count > 0) { - writer.WriteStringValue(nestedParameterItem); - } + writer.WriteStartArray("nestedParameter"u8); - writer.WriteEndArray(); + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -225,32 +265,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - writer.WriteStartArray("elementUsage"u8); - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + if (nestedElement.ElementUsage.Count > 0) { + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -258,14 +310,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("nestedParameter"u8); - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + if (nestedElement.NestedParameter.Count > 0) { - writer.WriteStringValue(nestedParameterItem); - } + writer.WriteStartArray("nestedParameter"u8); - writer.WriteEndArray(); + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -337,17 +393,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("elementUsage"u8); - - if(value is IEnumerable objectListElementUsage) + if (value is IEnumerable objectListElementUsage && objectListElementUsage.Any()) { + writer.WriteStartArray("elementUsage"u8); + foreach(var elementUsageItem in objectListElementUsage.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(elementUsageItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -355,17 +410,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -373,17 +427,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -445,17 +498,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("nestedParameter"u8); - - if(value is IEnumerable objectListNestedParameter) + if (value is IEnumerable objectListNestedParameter && objectListNestedParameter.Any()) { + writer.WriteStartArray("nestedParameter"u8); + foreach(var nestedParameterItem in objectListNestedParameter.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(nestedParameterItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index ead620444..5445c894a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -124,23 +124,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -174,23 +182,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -237,23 +253,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (nestedParameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -387,17 +411,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -405,17 +428,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "formula": if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 31a6ead32..93208c265 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -90,23 +90,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -121,23 +129,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -165,23 +181,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (notExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -257,17 +281,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -275,17 +298,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 7090d29fd..752c91ce6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,56 +77,76 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + if (option.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + if (option.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + if (option.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (option.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if (option.NestedElement.Count > 0) { - writer.WriteStringValue(nestedElementItem); - } + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -135,61 +155,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + if (option.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + if (option.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + if (option.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (option.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -197,14 +241,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if (option.NestedElement.Count > 0) { - writer.WriteStringValue(nestedElementItem); - } + writer.WriteStartArray("nestedElement"u8); - writer.WriteEndArray(); + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -213,61 +261,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + if (option.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + if (option.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + if (option.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (option.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -275,14 +347,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if (option.NestedElement.Count > 0) { - writer.WriteStringValue(nestedElementItem); - } + writer.WriteStartArray("nestedElement"u8); - writer.WriteEndArray(); + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -304,61 +380,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + if (option.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + if (option.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + if (option.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (option.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (option.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -366,14 +465,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - writer.WriteStartArray("nestedElement"u8); - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + if (option.NestedElement.Count > 0) { - writer.WriteStringValue(nestedElementItem); - } + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -427,17 +530,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -445,17 +547,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -481,17 +582,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -499,17 +599,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -517,17 +616,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -535,17 +633,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -607,17 +704,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("nestedElement"u8); - - if(value is IEnumerable objectListNestedElement) + if (value is IEnumerable objectListNestedElement && objectListNestedElement.Any()) { + writer.WriteStartArray("nestedElement"u8); + foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(nestedElementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index 5cd8ddfb5..a0f4195cc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -83,37 +83,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (orExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -121,37 +133,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (orExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -159,14 +183,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (orExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); @@ -186,23 +214,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (orExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -210,14 +246,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - writer.WriteStartArray("term"u8); - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + if (orExpression.Term.Count > 0) { - writer.WriteStringValue(termItem); - } + writer.WriteStartArray("term"u8); - writer.WriteEndArray(); + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); @@ -285,17 +325,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -303,17 +342,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -375,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("term"u8); - - if(value is IEnumerable objectListTerm) + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { + writer.WriteStartArray("term"u8); + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(termItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 33ee7da57..ea5721c2a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -143,64 +159,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -210,14 +250,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -241,64 +285,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -308,14 +376,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -341,14 +413,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -364,52 +440,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -419,14 +514,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -452,14 +551,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ordinalScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -507,17 +610,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -543,17 +645,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -561,17 +662,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -579,17 +679,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -597,17 +696,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -687,17 +785,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("mappingToReferenceScale"u8); - - if(value is IEnumerable objectListMappingToReferenceScale) + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { + writer.WriteStartArray("mappingToReferenceScale"u8); + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(mappingToReferenceScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "maximumpermissiblevalue": if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) @@ -921,17 +1018,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the OrdinalScale"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 5c96221c0..1884c3192 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -94,23 +94,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -129,23 +137,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -177,23 +193,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (organization.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -273,17 +297,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -291,17 +314,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index cddea0cef..84c47dfbd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (organizationalParticipant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (organizationalParticipant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -123,23 +131,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (organizationalParticipant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (organizationalParticipant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -215,17 +231,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -233,17 +248,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index a85d891e5..5f714d67f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -228,37 +236,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -393,14 +412,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); - writer.WriteEndArray(); + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -418,23 +441,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -569,14 +600,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (ownedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -642,17 +677,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -660,17 +694,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "fillcolor": if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) @@ -984,17 +1017,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("usedColor"u8); - - if(value is IEnumerable objectListUsedColor) + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) { + writer.WriteStartArray("usedColor"u8); + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(usedColorItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index d2820f39d..974d66cea 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + if (page.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (page.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -132,36 +148,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + if (page.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -169,14 +197,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (page.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -200,36 +232,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + if (page.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (page.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -237,14 +280,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - writer.WriteStartArray("note"u8); - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + if (page.Note.Count > 0) { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -300,17 +347,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -354,17 +400,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -372,17 +417,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -444,17 +488,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("note"u8); - - if(value is IEnumerable objectListNote) + if (value is IEnumerable objectListNote && objectListNote.Any()) { + writer.WriteStartArray("note"u8); + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(noteItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "owner": if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index 81f5146b0..f23c6492a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -112,23 +112,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -154,23 +161,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -209,23 +223,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -319,17 +340,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -337,17 +357,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index c3be67cda..8a7b799b1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,48 +85,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -136,48 +152,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -187,27 +219,35 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -225,23 +265,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -251,27 +299,35 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterOverride.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -337,17 +393,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -355,17 +410,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -445,17 +499,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterSubscription"u8); - - if(value is IEnumerable objectListParameterSubscription) + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) { + writer.WriteStartArray("parameterSubscription"u8); + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterSubscriptionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -499,17 +552,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueSet"u8); - - if(value is IEnumerable objectListValueSet) + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { + writer.WriteStartArray("valueSet"u8); + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueSetItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverride"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 1c3b80807..778785534 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -98,23 +98,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -136,23 +144,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -187,23 +203,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterOverrideValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -293,17 +317,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -311,17 +334,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "formula": if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index edb35c055..fc9ef482a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -100,14 +100,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.IsOptionDependent); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameter.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); - writer.WriteEndArray(); + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -146,14 +150,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameter.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": @@ -162,23 +169,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -201,14 +216,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameter.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -247,14 +266,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameter.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": @@ -263,23 +285,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -302,14 +332,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameter.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); - writer.WriteEndArray(); + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -350,14 +384,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameter.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -377,23 +415,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameter.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -416,14 +462,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - writer.WriteStartArray("parameterSubscription"u8); - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + if (parameter.ParameterSubscription.Count > 0) { - writer.WriteStringValue(parameterSubscriptionItem); - } + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -464,14 +514,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameter.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -555,17 +609,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -573,17 +626,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "expectsoverride": if(!AllowedVersionsPerProperty["expectsOverride"].Contains(requestedVersion)) @@ -699,17 +751,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterSubscription"u8); - - if(value is IEnumerable objectListParameterSubscription) + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) { + writer.WriteStartArray("parameterSubscription"u8); + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterSubscriptionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "parametertype": if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) @@ -825,17 +876,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueSet"u8); - - if(value is IEnumerable objectListValueSet) + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { + writer.WriteStartArray("valueSet"u8); + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueSetItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 6832b54a2..5ba2383a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,37 +85,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterSubscription.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -125,37 +137,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterSubscription.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -167,14 +191,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterSubscription.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); - writer.WriteEndArray(); + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -192,23 +220,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -220,14 +256,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterSubscription.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); - writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscription.ValueSet.Count > 0) { - writer.WriteStringValue(valueSetItem); - } + writer.WriteStartArray("valueSet"u8); - writer.WriteEndArray(); + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + } break; default: @@ -293,17 +333,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -311,17 +350,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -419,17 +457,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueSet"u8); - - if(value is IEnumerable objectListValueSet) + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { + writer.WriteStartArray("valueSet"u8); + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueSetItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscription"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 41371a9c3..940b861be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -93,23 +93,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -127,23 +135,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -174,23 +190,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -269,17 +293,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -287,17 +310,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 2c5253535..c114fa1dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -103,23 +103,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -147,23 +155,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -204,23 +220,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterTypeComponent.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -309,17 +333,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -327,17 +350,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 56326cec5..5503bc178 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -140,23 +140,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -198,23 +206,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -269,23 +285,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterValueSet.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -409,17 +433,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -427,17 +450,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "formula": if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index a55f0d555..076301508 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -130,54 +146,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -187,14 +223,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -203,54 +243,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -260,14 +320,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -289,54 +353,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -346,14 +429,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (parameterizedCategoryRule.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -461,17 +547,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +564,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +581,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +598,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -605,17 +687,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterType"u8); - - if(value is IEnumerable objectListParameterType) + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { + writer.WriteStartArray("parameterType"u8); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 225ac2c7e..0efb4f32e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,14 +79,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - writer.WriteStartArray("expression"u8); - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.Expression.Count > 0) { - writer.WriteStringValue(expressionItem); - } + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -108,32 +112,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("expression"u8); - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.Expression.Count > 0) { - writer.WriteStringValue(expressionItem); - } + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -157,32 +173,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("expression"u8); - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.Expression.Count > 0) { - writer.WriteStringValue(expressionItem); - } + writer.WriteStartArray("expression"u8); - writer.WriteEndArray(); + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -219,32 +247,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("expression"u8); - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + if (parametricConstraint.Expression.Count > 0) { - writer.WriteStringValue(expressionItem); - } + writer.WriteStartArray("expression"u8); - writer.WriteEndArray(); + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -329,17 +369,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -347,17 +386,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "expression": if(!AllowedVersionsPerProperty["expression"].Contains(requestedVersion)) @@ -365,17 +403,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("expression"u8); - - if(value is IEnumerable objectListExpression) + if (value is IEnumerable objectListExpression && objectListExpression.Any()) { + writer.WriteStartArray("expression"u8); + foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(expressionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index 1f5e997d1..fc16aaadb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -96,23 +96,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -131,23 +139,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -179,23 +195,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -291,17 +315,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -309,17 +332,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 6e9fdced3..41959237b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (participantRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -112,14 +124,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(participantRole.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ParticipantPermission.Count > 0) { - writer.WriteStringValue(participantPermissionItem); - } + writer.WriteStartArray("participantPermission"u8); - writer.WriteEndArray(); + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -128,52 +144,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (participantRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -183,14 +219,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ParticipantPermission.Count > 0) { - writer.WriteStringValue(participantPermissionItem); - } + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -199,52 +239,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (participantRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -254,14 +314,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ParticipantPermission.Count > 0) { - writer.WriteStringValue(participantPermissionItem); - } + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -283,52 +347,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (participantRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (participantRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -338,14 +421,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - writer.WriteStartArray("participantPermission"u8); - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + if (participantRole.ParticipantPermission.Count > 0) { - writer.WriteStringValue(participantPermissionItem); - } + writer.WriteStartArray("participantPermission"u8); - writer.WriteEndArray(); + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -435,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -579,17 +661,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("participantPermission"u8); - - if(value is IEnumerable objectListParticipantPermission) + if (value is IEnumerable objectListParticipantPermission && objectListParticipantPermission.Any()) { + writer.WriteStartArray("participantPermission"u8); + foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(participantPermissionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index 1f162cfc0..22509c97e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,14 +79,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + if (participant.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -105,32 +109,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + if (participant.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -151,32 +167,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + if (participant.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -210,32 +238,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + if (participant.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (participant.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -317,17 +357,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domain"u8); - - if(value is IEnumerable objectListDomain) + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { + writer.WriteStartArray("domain"u8); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -335,17 +374,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -353,17 +391,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index a9ffb3fa6..e35673f8b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -96,23 +96,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -131,23 +139,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -179,23 +195,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personPermission.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -291,17 +315,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -309,17 +332,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 780e0d508..e229e7085 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (personRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (personRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (personRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -112,14 +124,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(personRole.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + if (personRole.PersonPermission.Count > 0) { - writer.WriteStringValue(personPermissionItem); - } + writer.WriteStartArray("personPermission"u8); - writer.WriteEndArray(); + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -128,52 +144,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (personRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (personRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (personRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -183,14 +219,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + if (personRole.PersonPermission.Count > 0) { - writer.WriteStringValue(personPermissionItem); - } + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -199,52 +239,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (personRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (personRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (personRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -254,14 +314,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + if (personRole.PersonPermission.Count > 0) { - writer.WriteStringValue(personPermissionItem); - } + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -283,52 +347,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + if (personRole.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + if (personRole.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (personRole.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (personRole.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -338,14 +421,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - writer.WriteStartArray("personPermission"u8); - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + if (personRole.PersonPermission.Count > 0) { - writer.WriteStringValue(personPermissionItem); - } + writer.WriteStartArray("personPermission"u8); - writer.WriteEndArray(); + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -435,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -579,17 +661,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("personPermission"u8); - - if(value is IEnumerable objectListPersonPermission) + if (value is IEnumerable objectListPersonPermission && objectListPersonPermission.Any()) { + writer.WriteStartArray("personPermission"u8); + foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(personPermissionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index 5c6802131..e626ed3e1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -112,14 +112,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + if (person.EmailAddress.Count > 0) { - writer.WriteStringValue(emailAddressItem); - } + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -161,23 +164,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + if (person.TelephoneNumber.Count > 0) { - writer.WriteStringValue(telephoneNumberItem); - } + writer.WriteStartArray("telephoneNumber"u8); - writer.WriteEndArray(); + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("userPreference"u8); - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + if (person.UserPreference.Count > 0) { - writer.WriteStringValue(userPreferenceItem); - } + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": @@ -217,32 +228,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + if (person.EmailAddress.Count > 0) { - writer.WriteStringValue(emailAddressItem); - } + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -286,23 +308,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + if (person.TelephoneNumber.Count > 0) { - writer.WriteStringValue(telephoneNumberItem); - } + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("userPreference"u8); - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + if (person.UserPreference.Count > 0) { - writer.WriteStringValue(userPreferenceItem); - } + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": @@ -342,32 +372,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + if (person.EmailAddress.Count > 0) { - writer.WriteStringValue(emailAddressItem); - } + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -411,25 +452,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + if (person.TelephoneNumber.Count > 0) { - writer.WriteStringValue(telephoneNumberItem); - } + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); - writer.WriteStartArray("userPreference"u8); - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + if (person.UserPreference.Count > 0) { - writer.WriteStringValue(userPreferenceItem); - } + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -480,32 +529,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("emailAddress"u8); - - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + if (person.EmailAddress.Count > 0) { - writer.WriteStringValue(emailAddressItem); - } + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (person.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -549,25 +609,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - writer.WriteStartArray("telephoneNumber"u8); - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + if (person.TelephoneNumber.Count > 0) { - writer.WriteStringValue(telephoneNumberItem); - } + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); - writer.WriteStartArray("userPreference"u8); - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + if (person.UserPreference.Count > 0) { - writer.WriteStringValue(userPreferenceItem); - } + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -687,17 +755,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("emailAddress"u8); - - if(value is IEnumerable objectListEmailAddress) + if (value is IEnumerable objectListEmailAddress && objectListEmailAddress.Any()) { + writer.WriteStartArray("emailAddress"u8); + foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(emailAddressItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -705,17 +772,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -723,17 +789,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "givenname": if(!AllowedVersionsPerProperty["givenName"].Contains(requestedVersion)) @@ -957,17 +1022,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("telephoneNumber"u8); - - if(value is IEnumerable objectListTelephoneNumber) + if (value is IEnumerable objectListTelephoneNumber && objectListTelephoneNumber.Any()) { + writer.WriteStartArray("telephoneNumber"u8); + foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(telephoneNumberItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) @@ -993,17 +1057,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("userPreference"u8); - - if(value is IEnumerable objectListUserPreference) + if (value is IEnumerable objectListUserPreference && objectListUserPreference.Any()) { + writer.WriteStartArray("userPreference"u8); + foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(userPreferenceItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 4140edf0e..8092cb650 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -114,23 +122,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -162,23 +178,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (point.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -258,17 +282,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -276,17 +299,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 4c5bea084..6248389a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,23 +77,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -108,23 +116,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -132,14 +147,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + if (possibleFiniteStateList.PossibleState.Count > 0) { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -148,23 +167,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -179,41 +206,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -223,14 +265,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + if (possibleFiniteStateList.PossibleState.Count > 0) { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -239,23 +285,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -270,41 +324,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -314,14 +383,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + if (possibleFiniteStateList.PossibleState.Count > 0) { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -343,23 +416,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -374,41 +454,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteStateList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -418,14 +513,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - writer.WriteStartArray("possibleState"u8); - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + if (possibleFiniteStateList.PossibleState.Count > 0) { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -479,17 +578,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -497,17 +595,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -551,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -569,17 +665,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -587,17 +682,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -605,17 +699,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -695,17 +788,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleState"u8); - - if(value is IEnumerable objectListPossibleState) + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) { + writer.WriteStartArray("possibleState"u8); + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(possibleStateItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index 0d47f7b5c..b7f0dfd42 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -117,52 +129,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -177,52 +209,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -250,52 +302,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (possibleFiniteState.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -355,17 +426,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -391,17 +461,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -409,17 +478,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -427,17 +495,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -445,17 +512,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index 42104de74..32c9dc562 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -119,52 +131,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -181,52 +213,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -256,52 +308,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (prefixedUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -363,17 +434,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -399,17 +469,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -417,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -435,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -453,17 +520,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index d1beffcf6..2746ad99e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -81,25 +81,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + if (publication.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); - writer.WriteStartArray("publishedParameter"u8); - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + if (publication.PublishedParameter.Count > 0) { - writer.WriteStringValue(publishedParameterItem); - } + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -110,45 +118,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + if (publication.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + if (publication.PublishedParameter.Count > 0) { - writer.WriteStringValue(publishedParameterItem); - } + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -159,45 +183,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + if (publication.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + if (publication.PublishedParameter.Count > 0) { - writer.WriteStringValue(publishedParameterItem); - } + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -221,45 +261,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("domain"u8); - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + if (publication.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (publication.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("publishedParameter"u8); - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + if (publication.PublishedParameter.Count > 0) { - writer.WriteStringValue(publishedParameterItem); - } + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -347,17 +403,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domain"u8); - - if(value is IEnumerable objectListDomain) + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { + writer.WriteStartArray("domain"u8); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -365,17 +420,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -383,17 +437,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -437,17 +490,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("publishedParameter"u8); - - if(value is IEnumerable objectListPublishedParameter) + if (value is IEnumerable objectListPublishedParameter && objectListPublishedParameter.Any()) { + writer.WriteStartArray("publishedParameter"u8); + foreach(var publishedParameterItem in objectListPublishedParameter.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(publishedParameterItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 966d9d818..3a99188b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (quantityKindFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "exponent": if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index b7edfc24c..c0433aa67 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -114,14 +126,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -141,64 +157,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -208,14 +248,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); - writer.WriteEndArray(); + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -237,64 +281,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -304,14 +372,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -335,14 +407,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); - writer.WriteEndArray(); + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -358,52 +434,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -413,14 +508,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - writer.WriteStartArray("mappingToReferenceScale"u8); - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.MappingToReferenceScale.Count > 0) { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -444,14 +543,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - writer.WriteStartArray("valueDefinition"u8); - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + if (ratioScale.ValueDefinition.Count > 0) { - writer.WriteStringValue(valueDefinitionItem); - } + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -499,17 +602,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -535,17 +637,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -553,17 +654,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -571,17 +671,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -589,17 +688,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -679,17 +777,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("mappingToReferenceScale"u8); - - if(value is IEnumerable objectListMappingToReferenceScale) + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { + writer.WriteStartArray("mappingToReferenceScale"u8); + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(mappingToReferenceScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "maximumpermissiblevalue": if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) @@ -895,17 +992,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueDefinition"u8); - - if(value is IEnumerable objectListValueDefinition) + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { + writer.WriteStartArray("valueDefinition"u8); + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueDefinitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index c0b47518b..c158b922c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -178,63 +194,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -299,63 +339,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -433,63 +497,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referenceSource.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -599,17 +686,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -635,17 +721,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -671,17 +756,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -689,17 +773,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -707,17 +790,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -725,17 +807,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index 36b9ef62a..af4f1f55a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -116,14 +128,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(referencerRule.MinReferenced); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ReferencedCategory.Count > 0) { - writer.WriteStringValue(referencedCategoryItem); - } + writer.WriteStartArray("referencedCategory"u8); - writer.WriteEndArray(); + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -134,52 +150,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -193,14 +229,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ReferencedCategory.Count > 0) { - writer.WriteStringValue(referencedCategoryItem); - } + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -211,52 +251,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -270,14 +330,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ReferencedCategory.Count > 0) { - writer.WriteStringValue(referencedCategoryItem); - } + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -301,52 +365,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -360,14 +443,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - writer.WriteStartArray("referencedCategory"u8); - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + if (referencerRule.ReferencedCategory.Count > 0) { - writer.WriteStringValue(referencedCategoryItem); - } + writer.WriteStartArray("referencedCategory"u8); - writer.WriteEndArray(); + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -423,17 +510,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -459,17 +545,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -477,17 +562,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -495,17 +579,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -513,17 +596,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -639,17 +721,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("referencedCategory"u8); - - if(value is IEnumerable objectListReferencedCategory) + if (value is IEnumerable objectListReferencedCategory && objectListReferencedCategory.Any()) { + writer.WriteStartArray("referencedCategory"u8); + foreach(var referencedCategoryItem in objectListReferencedCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(referencedCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "referencingcategory": if(!AllowedVersionsPerProperty["referencingCategory"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index dd52a2064..95f88bdd9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -104,23 +104,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -149,23 +157,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -207,23 +223,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationalExpression.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -313,17 +337,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -331,17 +354,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 751c35b7c..82c62a34f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -122,23 +130,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -178,23 +194,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (relationshipParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -282,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -300,17 +323,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 8aabd337b..1a188619d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -105,32 +113,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -151,27 +171,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -180,25 +207,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -208,32 +243,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -254,27 +301,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -296,25 +350,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -324,32 +385,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -370,27 +443,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForDeviation.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -444,17 +524,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -480,17 +559,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classification": if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) @@ -570,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -588,17 +665,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -606,17 +682,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -714,17 +789,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -768,17 +842,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index e083024a7..2b0e14484 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -105,32 +113,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -151,27 +171,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -180,25 +207,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -208,32 +243,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -254,27 +301,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -296,25 +350,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -324,32 +385,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -370,27 +443,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (requestForWaiver.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -444,17 +524,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -480,17 +559,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classification": if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) @@ -570,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -588,17 +665,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -606,17 +682,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -714,17 +789,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -768,17 +842,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 5edc2e7d7..03da10358 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirement.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if (requirement.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirement.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("group"u8); @@ -117,14 +129,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirement.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -134,23 +149,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirement.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("parametricConstraint"u8); - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + if (requirement.ParametricConstraint.Count > 0) { + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -159,52 +182,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirement.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if (requirement.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirement.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("group"u8); @@ -217,14 +260,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirement.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -236,23 +282,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirement.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("parametricConstraint"u8); - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + if (requirement.ParametricConstraint.Count > 0) { + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -261,52 +315,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirement.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if (requirement.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirement.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("group"u8); @@ -319,14 +393,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirement.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -338,23 +415,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirement.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("parametricConstraint"u8); - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + if (requirement.ParametricConstraint.Count > 0) { + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -376,52 +461,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirement.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + if (requirement.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirement.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirement.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("group"u8); @@ -434,14 +538,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirement.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -453,23 +560,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirement.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("parametricConstraint"u8); - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + if (requirement.ParametricConstraint.Count > 0) { + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -523,17 +638,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -541,17 +655,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -577,17 +690,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -595,17 +707,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -613,17 +724,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "group": if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) @@ -649,17 +759,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -757,17 +866,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterValue"u8); - - if(value is IEnumerable objectListParameterValue) + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { + writer.WriteStartArray("parameterValue"u8); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "parametricconstraint": if(!AllowedVersionsPerProperty["parametricConstraint"].Contains(requestedVersion)) @@ -775,17 +883,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parametricConstraint"u8); - - if(value is IEnumerable objectListParametricConstraint) + if (value is IEnumerable objectListParametricConstraint && objectListParametricConstraint.Any()) { + writer.WriteStartArray("parametricConstraint"u8); + foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(parametricConstraintItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index cd791bb98..89ff37048 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -122,23 +130,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -178,23 +194,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -282,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -300,17 +323,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 31cc56d6e..a63442b82 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); - writer.WriteEndArray(); + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -128,70 +144,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); - writer.WriteEndArray(); + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -201,14 +245,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -217,70 +265,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); - writer.WriteEndArray(); + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -290,14 +366,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); - writer.WriteEndArray(); + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -319,70 +399,97 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -392,14 +499,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsGroup.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -453,17 +564,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -471,17 +581,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -507,17 +616,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -525,17 +633,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -543,17 +650,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "group": if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) @@ -561,17 +667,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("group"u8); - - if(value is IEnumerable objectListGroup) + if (value is IEnumerable objectListGroup && objectListGroup.Any()) { + writer.WriteStartArray("group"u8); + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(groupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -579,17 +684,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -669,17 +773,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterValue"u8); - - if(value is IEnumerable objectListParameterValue) + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { + writer.WriteStartArray("parameterValue"u8); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index a237a7fb8..31939fb0f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -123,14 +139,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); - writer.WriteEndArray(); + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -139,70 +159,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -214,23 +262,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -239,70 +295,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -314,23 +398,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); - writer.WriteEndArray(); + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -352,70 +444,97 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("group"u8); - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Group.Count > 0) { - writer.WriteStringValue(groupItem); - } + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -427,23 +546,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - writer.WriteStartArray("parameterValue"u8); - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.ParameterValue.Count > 0) { - writer.WriteStringValue(parameterValueItem); - } + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + if (requirementsSpecification.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); - writer.WriteEndArray(); + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -497,17 +624,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -515,17 +641,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -551,17 +676,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -569,17 +693,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -587,17 +710,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "group": if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) @@ -605,17 +727,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("group"u8); - - if(value is IEnumerable objectListGroup) + if (value is IEnumerable objectListGroup && objectListGroup.Any()) { + writer.WriteStartArray("group"u8); + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(groupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -623,17 +744,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -731,17 +851,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterValue"u8); - - if(value is IEnumerable objectListParameterValue) + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { + writer.WriteStartArray("parameterValue"u8); + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "requirement": if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) @@ -749,17 +868,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("requirement"u8); - - if(value is IEnumerable objectListRequirement) + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) { + writer.WriteStartArray("requirement"u8); + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(requirementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index bd78f1344..70bd29ba4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,25 +77,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -105,32 +113,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -151,36 +171,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Solution.Count > 0) { - writer.WriteStringValue(solutionItem); - } + writer.WriteStartArray("solution"u8); - writer.WriteEndArray(); + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -189,25 +220,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -217,32 +256,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -263,36 +314,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Solution.Count > 0) { - writer.WriteStringValue(solutionItem); - } + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -314,25 +376,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ApprovedBy.Count > 0) { - writer.WriteStringValue(approvedByItem); - } + writer.WriteStartArray("approvedBy"u8); - writer.WriteEndArray(); + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -342,32 +411,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -388,36 +469,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - writer.WriteStartArray("solution"u8); - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.Solution.Count > 0) { - writer.WriteStringValue(solutionItem); - } + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("sourceAnnotation"u8); - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) { - writer.WriteStringValue(sourceAnnotationItem); - } + writer.WriteStartArray("sourceAnnotation"u8); - writer.WriteEndArray(); + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -471,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("approvedBy"u8); - - if(value is IEnumerable objectListApprovedBy) + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { + writer.WriteStartArray("approvedBy"u8); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(approvedByItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -507,17 +598,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classification": if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) @@ -597,17 +687,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -615,17 +704,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -633,17 +721,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -741,17 +828,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -795,17 +881,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("solution"u8); - - if(value is IEnumerable objectListSolution) + if (value is IEnumerable objectListSolution && objectListSolution.Any()) { + writer.WriteStartArray("solution"u8); + foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(solutionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "sourceannotation": if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) @@ -813,17 +898,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("sourceAnnotation"u8); - - if(value is IEnumerable objectListSourceAnnotation) + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { + writer.WriteStartArray("sourceAnnotation"u8); + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(sourceAnnotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "status": if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index 5cf08a6b8..ba7f87a50 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -114,66 +126,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + if (ruleVerificationList.RuleVerification.Count > 0) { + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -185,66 +221,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + if (ruleVerificationList.RuleVerification.Count > 0) { + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -256,14 +316,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + if (ruleVerificationList.RuleVerification.Count > 0) { + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -283,52 +347,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (ruleVerificationList.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -340,14 +423,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - writer.WriteStartArray("ruleVerification"u8); - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + if (ruleVerificationList.RuleVerification.Count > 0) { + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -399,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -435,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -453,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -471,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -489,17 +572,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -597,17 +679,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("ruleVerification"u8); - - if(value is IEnumerable objectListRuleVerification) + if (value is IEnumerable objectListRuleVerification && objectListRuleVerification.Any()) { + writer.WriteStartArray("ruleVerification"u8); + foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(ruleVerificationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shortname": if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index a37d9bcd0..8b4e5c707 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,14 +85,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WriteStartArray("violatingThing"u8); - foreach(var violatingThingItem in ruleViolation.ViolatingThing) + if (ruleViolation.ViolatingThing.Count > 0) { - writer.WriteStringValue(violatingThingItem); - } + writer.WriteStartArray("violatingThing"u8); - writer.WriteEndArray(); + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + } break; case "1.1.0": @@ -101,23 +105,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -125,14 +137,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); - writer.WriteStartArray("violatingThing"u8); - foreach(var violatingThingItem in ruleViolation.ViolatingThing) + if (ruleViolation.ViolatingThing.Count > 0) { - writer.WriteStringValue(violatingThingItem); - } + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": @@ -141,23 +157,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -167,14 +191,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ruleViolation.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); - writer.WriteStartArray("violatingThing"u8); - foreach(var violatingThingItem in ruleViolation.ViolatingThing) + if (ruleViolation.ViolatingThing.Count > 0) { - writer.WriteStringValue(violatingThingItem); - } + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -194,23 +222,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (ruleViolation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -220,14 +256,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ruleViolation.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); - writer.WriteStartArray("violatingThing"u8); - foreach(var violatingThingItem in ruleViolation.ViolatingThing) + if (ruleViolation.ViolatingThing.Count > 0) { - writer.WriteStringValue(violatingThingItem); - } + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -311,17 +351,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -329,17 +368,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -419,17 +457,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("violatingThing"u8); - - if(value is IEnumerable objectListViolatingThing) + if (value is IEnumerable objectListViolatingThing && objectListViolatingThing.Any()) { - foreach(var violatingThingItem in objectListViolatingThing) + writer.WriteStartArray("violatingThing"u8); + + foreach (var violatingThingItem in objectListViolatingThing) { writer.WriteStringValue((Guid)violatingThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleViolation"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index 80cb84791..bfb4a6843 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("degreeOfInterpolation"u8); @@ -117,52 +129,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("dependentParameterType"u8); - - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + if (sampledFunctionParameterType.DependentParameterType.Count > 0) { + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dependentParameterTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); - writer.WriteStartArray("independentParameterType"u8); - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + if (sampledFunctionParameterType.IndependentParameterType.Count > 0) { + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(independentParameterTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -193,34 +224,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("degreeOfInterpolation"u8); @@ -233,52 +275,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("dependentParameterType"u8); - - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + if (sampledFunctionParameterType.DependentParameterType.Count > 0) { + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dependentParameterTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (sampledFunctionParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); - writer.WriteStartArray("independentParameterType"u8); - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + if (sampledFunctionParameterType.IndependentParameterType.Count > 0) { + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(independentParameterTypeItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -341,17 +402,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -359,17 +419,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -395,17 +454,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "degreeofinterpolation": if(!AllowedVersionsPerProperty["degreeOfInterpolation"].Contains(requestedVersion)) @@ -431,17 +489,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("dependentParameterType"u8); - - if(value is IEnumerable objectListDependentParameterType) + if (value is IEnumerable objectListDependentParameterType && objectListDependentParameterType.Any()) { + writer.WriteStartArray("dependentParameterType"u8); + foreach(var dependentParameterTypeItem in objectListDependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(dependentParameterTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -449,17 +506,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -467,17 +523,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -485,17 +540,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -521,17 +575,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("independentParameterType"u8); - - if(value is IEnumerable objectListIndependentParameterType) + if (value is IEnumerable objectListIndependentParameterType && objectListIndependentParameterType.Any()) { + writer.WriteStartArray("independentParameterType"u8); + foreach(var independentParameterTypeItem in objectListIndependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(independentParameterTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "interpolationperiod": if(!AllowedVersionsPerProperty["interpolationPeriod"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index 5852aa471..a12329c16 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index b1adb3c9b..b47506d6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -119,52 +131,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -181,52 +213,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -256,52 +308,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (scaleValueDefinition.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -363,17 +434,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -399,17 +469,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -417,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -435,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -453,17 +520,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 3d4aa0bf9..b9ac65c0f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + if (section.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -116,14 +128,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + if (section.Page.Count > 0) { + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -132,36 +148,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + if (section.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -171,14 +199,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + if (section.Page.Count > 0) { + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -200,36 +232,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + if (section.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (section.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -239,14 +282,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - writer.WriteStartArray("page"u8); - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + if (section.Page.Count > 0) { + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -300,17 +347,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -354,17 +400,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -372,17 +417,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -462,17 +506,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("page"u8); - - if(value is IEnumerable objectListPage) + if (value is IEnumerable objectListPage && objectListPage.Any()) { + writer.WriteStartArray("page"u8); + foreach(var pageItem in objectListPage.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(pageItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index 2ced7f763..7508e4390 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -228,37 +236,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -393,14 +412,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); - writer.WriteEndArray(); + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -418,23 +441,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("fillColor"u8); @@ -569,14 +600,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); - writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + if (sharedStyle.UsedColor.Count > 0) { - writer.WriteStringValue(usedColorItem); - } + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -642,17 +677,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -660,17 +694,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "fillcolor": if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) @@ -984,17 +1017,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("usedColor"u8); - - if(value is IEnumerable objectListUsedColor) + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) { + writer.WriteStartArray("usedColor"u8); + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(usedColorItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 4abe7173d..8356dd5f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -102,23 +102,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -145,23 +153,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -201,23 +217,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleParameterValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -305,17 +329,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -323,17 +346,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index 0381206b4..fe28344e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,45 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -123,14 +139,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -143,63 +163,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -209,14 +253,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); - writer.WriteEndArray(); + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -229,63 +277,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -295,14 +367,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); - writer.WriteEndArray(); + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -328,63 +404,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -394,14 +493,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (simpleQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -459,17 +562,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -477,17 +579,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -531,17 +632,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -549,17 +649,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -567,17 +666,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -585,17 +683,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -675,17 +772,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleScale"u8); - - if(value is IEnumerable objectListPossibleScale) + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { + writer.WriteStartArray("possibleScale"u8); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "quantitydimensionsymbol": if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 95afddc3b..f37df4cd9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -119,52 +131,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -181,52 +213,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -256,52 +308,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (simpleUnit.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -363,17 +434,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -399,17 +469,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -417,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -435,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -453,17 +520,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 727c19091..511776d45 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,32 +85,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -120,14 +132,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -142,32 +158,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); - writer.WriteEndArray(); + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -177,14 +205,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -212,32 +244,44 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("discussion"u8); - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.Discussion.Count > 0) { - writer.WriteStringValue(discussionItem); - } + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -247,14 +291,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) { - writer.WriteStringValue(relatedThingItem); - } + writer.WriteStartArray("relatedThing"u8); - writer.WriteEndArray(); + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -378,17 +426,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("discussion"u8); - - if(value is IEnumerable objectListDiscussion) + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { + writer.WriteStartArray("discussion"u8); + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(discussionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -396,17 +443,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -414,17 +460,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -504,17 +549,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("relatedThing"u8); - - if(value is IEnumerable objectListRelatedThing) + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { + writer.WriteStartArray("relatedThing"u8); + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(relatedThingItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index 227f64e26..0b7294218 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,23 +85,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -133,23 +141,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -194,23 +210,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -351,17 +375,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -369,17 +392,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 64dd01191..8c9fb8430 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -103,117 +103,160 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("domainGroup"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.DomainGroup.Count > 0) { - writer.WriteStringValue(domainGroupItem); - } + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("model"u8); - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Model.Count > 0) { - writer.WriteStringValue(modelItem); - } + writer.WriteStartArray("model"u8); - writer.WriteEndArray(); + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.NaturalLanguage.Count > 0) { - writer.WriteStringValue(naturalLanguageItem); - } + writer.WriteStartArray("naturalLanguage"u8); - writer.WriteEndArray(); + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("organization"u8); - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Organization.Count > 0) { - writer.WriteStringValue(organizationItem); - } + writer.WriteStartArray("organization"u8); - writer.WriteEndArray(); + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participantRole"u8); - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ParticipantRole.Count > 0) { - writer.WriteStringValue(participantRoleItem); - } + writer.WriteStartArray("participantRole"u8); - writer.WriteEndArray(); + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("person"u8); - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Person.Count > 0) { - writer.WriteStringValue(personItem); - } + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("personRole"u8); - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.PersonRole.Count > 0) { - writer.WriteStringValue(personRoleItem); - } + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.SiteReferenceDataLibrary.Count > 0) { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); - writer.WriteStartArray("annotation"u8); - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Annotation.Count > 0) { - writer.WriteStringValue(annotationItem); - } + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -241,137 +284,188 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainGroup"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.DomainGroup.Count > 0) { - writer.WriteStringValue(domainGroupItem); - } + writer.WriteStartArray("domainGroup"u8); - writer.WriteEndArray(); + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("model"u8); - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Model.Count > 0) { - writer.WriteStringValue(modelItem); - } + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.NaturalLanguage.Count > 0) { - writer.WriteStringValue(naturalLanguageItem); - } + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("organization"u8); - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Organization.Count > 0) { - writer.WriteStringValue(organizationItem); - } + writer.WriteStartArray("organization"u8); - writer.WriteEndArray(); + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participantRole"u8); - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ParticipantRole.Count > 0) { - writer.WriteStringValue(participantRoleItem); - } + writer.WriteStartArray("participantRole"u8); - writer.WriteEndArray(); + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("person"u8); - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Person.Count > 0) { - writer.WriteStringValue(personItem); - } + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("personRole"u8); - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.PersonRole.Count > 0) { - writer.WriteStringValue(personRoleItem); - } + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.SiteReferenceDataLibrary.Count > 0) { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + writer.WriteStartArray("siteReferenceDataLibrary"u8); - writer.WriteEndArray(); + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); - writer.WriteStartArray("annotation"u8); - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Annotation.Count > 0) { - writer.WriteStringValue(annotationItem); - } + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -399,125 +493,172 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainGroup"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.DomainGroup.Count > 0) { - writer.WriteStringValue(domainGroupItem); - } + writer.WriteStartArray("domainGroup"u8); - writer.WriteEndArray(); + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("model"u8); - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Model.Count > 0) { - writer.WriteStringValue(modelItem); - } + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.NaturalLanguage.Count > 0) { - writer.WriteStringValue(naturalLanguageItem); - } + writer.WriteStartArray("naturalLanguage"u8); - writer.WriteEndArray(); + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("organization"u8); - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Organization.Count > 0) { - writer.WriteStringValue(organizationItem); - } + writer.WriteStartArray("organization"u8); - writer.WriteEndArray(); + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participantRole"u8); - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ParticipantRole.Count > 0) { - writer.WriteStringValue(participantRoleItem); - } + writer.WriteStartArray("participantRole"u8); - writer.WriteEndArray(); + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("person"u8); - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Person.Count > 0) { - writer.WriteStringValue(personItem); - } + writer.WriteStartArray("person"u8); - writer.WriteEndArray(); + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("personRole"u8); - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.PersonRole.Count > 0) { - writer.WriteStringValue(personRoleItem); - } + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.SiteReferenceDataLibrary.Count > 0) { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); @@ -535,14 +676,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Annotation.Count > 0) { - writer.WriteStringValue(annotationItem); - } + writer.WriteStartArray("annotation"u8); - writer.WriteEndArray(); + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -570,125 +714,172 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Domain.Count > 0) { - writer.WriteStringValue(domainItem); - } + writer.WriteStartArray("domain"u8); - writer.WriteEndArray(); + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("domainGroup"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.DomainGroup.Count > 0) { - writer.WriteStringValue(domainGroupItem); - } + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("logEntry"u8); - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.LogEntry.Count > 0) { - writer.WriteStringValue(logEntryItem); - } + writer.WriteStartArray("logEntry"u8); - writer.WriteEndArray(); + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("model"u8); - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Model.Count > 0) { - writer.WriteStringValue(modelItem); - } + writer.WriteStartArray("model"u8); - writer.WriteEndArray(); + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - writer.WriteStartArray("naturalLanguage"u8); - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.NaturalLanguage.Count > 0) { - writer.WriteStringValue(naturalLanguageItem); - } + writer.WriteStartArray("naturalLanguage"u8); - writer.WriteEndArray(); + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("organization"u8); - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Organization.Count > 0) { - writer.WriteStringValue(organizationItem); - } + writer.WriteStartArray("organization"u8); - writer.WriteEndArray(); + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("participantRole"u8); - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.ParticipantRole.Count > 0) { - writer.WriteStringValue(participantRoleItem); - } + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("person"u8); - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.Person.Count > 0) { - writer.WriteStringValue(personItem); - } + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("personRole"u8); - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.PersonRole.Count > 0) { - writer.WriteStringValue(personRoleItem); - } + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - writer.WriteStartArray("siteReferenceDataLibrary"u8); - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + if (siteDirectory.SiteReferenceDataLibrary.Count > 0) { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); @@ -738,17 +929,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("annotation"u8); - - if(value is IEnumerable objectListAnnotation) + if (value is IEnumerable objectListAnnotation && objectListAnnotation.Any()) { + writer.WriteStartArray("annotation"u8); + foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(annotationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -828,17 +1018,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domain"u8); - - if(value is IEnumerable objectListDomain) + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { + writer.WriteStartArray("domain"u8); + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "domaingroup": if(!AllowedVersionsPerProperty["domainGroup"].Contains(requestedVersion)) @@ -846,17 +1035,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("domainGroup"u8); - - if(value is IEnumerable objectListDomainGroup) + if (value is IEnumerable objectListDomainGroup && objectListDomainGroup.Any()) { + writer.WriteStartArray("domainGroup"u8); + foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(domainGroupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -864,17 +1052,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -882,17 +1069,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -936,17 +1122,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("logEntry"u8); - - if(value is IEnumerable objectListLogEntry) + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) { + writer.WriteStartArray("logEntry"u8); + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(logEntryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "model": if(!AllowedVersionsPerProperty["model"].Contains(requestedVersion)) @@ -954,17 +1139,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("model"u8); - - if(value is IEnumerable objectListModel) + if (value is IEnumerable objectListModel && objectListModel.Any()) { + writer.WriteStartArray("model"u8); + foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(modelItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) @@ -1008,17 +1192,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("naturalLanguage"u8); - - if(value is IEnumerable objectListNaturalLanguage) + if (value is IEnumerable objectListNaturalLanguage && objectListNaturalLanguage.Any()) { + writer.WriteStartArray("naturalLanguage"u8); + foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(naturalLanguageItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "organization": if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) @@ -1026,17 +1209,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("organization"u8); - - if(value is IEnumerable objectListOrganization) + if (value is IEnumerable objectListOrganization && objectListOrganization.Any()) { + writer.WriteStartArray("organization"u8); + foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(organizationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "participantrole": if(!AllowedVersionsPerProperty["participantRole"].Contains(requestedVersion)) @@ -1044,17 +1226,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("participantRole"u8); - - if(value is IEnumerable objectListParticipantRole) + if (value is IEnumerable objectListParticipantRole && objectListParticipantRole.Any()) { + writer.WriteStartArray("participantRole"u8); + foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(participantRoleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "person": if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) @@ -1062,17 +1243,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("person"u8); - - if(value is IEnumerable objectListPerson) + if (value is IEnumerable objectListPerson && objectListPerson.Any()) { + writer.WriteStartArray("person"u8); + foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(personItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "personrole": if(!AllowedVersionsPerProperty["personRole"].Contains(requestedVersion)) @@ -1080,17 +1260,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("personRole"u8); - - if(value is IEnumerable objectListPersonRole) + if (value is IEnumerable objectListPersonRole && objectListPersonRole.Any()) { + writer.WriteStartArray("personRole"u8); + foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(personRoleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -1134,17 +1313,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - if(value is IEnumerable objectListSiteReferenceDataLibrary) + if (value is IEnumerable objectListSiteReferenceDataLibrary && objectListSiteReferenceDataLibrary.Any()) { + writer.WriteStartArray("siteReferenceDataLibrary"u8); + foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(siteReferenceDataLibraryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 4600c357d..8e0f9b2c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -112,23 +120,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -158,23 +174,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteDirectoryThingReference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -252,17 +276,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -270,17 +293,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 407871d73..0a97b3316 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,23 +77,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + if (siteLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + if (siteLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -106,14 +114,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -132,23 +143,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + if (siteLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + if (siteLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -161,14 +180,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -176,23 +198,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -207,23 +237,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + if (siteLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); - writer.WriteEndArray(); + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + if (siteLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); - writer.WriteEndArray(); + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -236,14 +274,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -251,23 +292,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -275,14 +324,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.LogEntryChangelogItem.Count > 0) { - writer.WriteStringValue(logEntryChangelogItemItem); - } + writer.WriteStartArray("logEntryChangelogItem"u8); - writer.WriteEndArray(); + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -304,23 +357,30 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + if (siteLogEntry.AffectedDomainIid.Count > 0) { - writer.WriteStringValue(affectedDomainIidItem); - } + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("affectedItemIid"u8); - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + if (siteLogEntry.AffectedItemIid.Count > 0) { - writer.WriteStringValue(affectedItemIidItem); - } + writer.WriteStartArray("affectedItemIid"u8); - writer.WriteEndArray(); + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("author"u8); @@ -333,14 +393,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -348,23 +411,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -372,14 +443,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); - writer.WriteStartArray("logEntryChangelogItem"u8); - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + if (siteLogEntry.LogEntryChangelogItem.Count > 0) { - writer.WriteStringValue(logEntryChangelogItemItem); - } + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -433,17 +508,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("affectedDomainIid"u8); - - if(value is IEnumerable objectListAffectedDomainIid) + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) { - foreach(var affectedDomainIidItem in objectListAffectedDomainIid) + writer.WriteStartArray("affectedDomainIid"u8); + + foreach (var affectedDomainIidItem in objectListAffectedDomainIid) { writer.WriteStringValue((Guid)affectedDomainIidItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "affecteditemiid": if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) @@ -451,17 +525,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("affectedItemIid"u8); - - if(value is IEnumerable objectListAffectedItemIid) + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) { - foreach(var affectedItemIidItem in objectListAffectedItemIid) + writer.WriteStartArray("affectedItemIid"u8); + + foreach (var affectedItemIidItem in objectListAffectedItemIid) { writer.WriteStringValue((Guid)affectedItemIidItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "author": if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) @@ -487,17 +560,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -559,17 +631,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -577,17 +648,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -649,17 +719,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("logEntryChangelogItem"u8); - - if(value is IEnumerable objectListLogEntryChangelogItem) + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) { + writer.WriteStartArray("logEntryChangelogItem"u8); + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(logEntryChangelogItemItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "modifiedon": if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index d4efc9722..96d5f3ffc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,88 +77,124 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); - writer.WriteEndArray(); + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -166,23 +202,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -197,147 +241,207 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); - writer.WriteEndArray(); + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); - writer.WriteEndArray(); + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -347,23 +451,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); - writer.WriteEndArray(); + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); - writer.WriteEndArray(); + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -378,147 +490,207 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); - writer.WriteEndArray(); + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); - writer.WriteEndArray(); + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); - writer.WriteEndArray(); + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); - writer.WriteEndArray(); + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); - writer.WriteEndArray(); + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -528,23 +700,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -559,45 +739,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -613,106 +809,149 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.BaseUnit.Count > 0) { - writer.WriteStringValue(baseUnitItem); - } + writer.WriteStartArray("baseUnit"u8); - writer.WriteEndArray(); + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - writer.WriteStartArray("constant"u8); - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Constant.Count > 0) { - writer.WriteStringValue(constantItem); - } + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.DefinedCategory.Count > 0) { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.FileType.Count > 0) { - writer.WriteStringValue(fileTypeItem); - } + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Glossary.Count > 0) { - writer.WriteStringValue(glossaryItem); - } + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -722,23 +961,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ParameterType.Count > 0) { - writer.WriteStringValue(parameterTypeItem); - } + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.ReferenceSource.Count > 0) { - writer.WriteStringValue(referenceSourceItem); - } + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("requiredRdl"u8); @@ -753,45 +1000,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - writer.WriteStartArray("rule"u8); - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Rule.Count > 0) { - writer.WriteStringValue(ruleItem); - } + writer.WriteStartArray("rule"u8); - writer.WriteEndArray(); + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("scale"u8); - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Scale.Count > 0) { - writer.WriteStringValue(scaleItem); - } + writer.WriteStartArray("scale"u8); - writer.WriteEndArray(); + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); - writer.WriteStartArray("unit"u8); - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.Unit.Count > 0) { - writer.WriteStringValue(unitItem); - } + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + if (siteReferenceDataLibrary.UnitPrefix.Count > 0) { - writer.WriteStringValue(unitPrefixItem); - } + writer.WriteStartArray("unitPrefix"u8); - writer.WriteEndArray(); + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + } break; default: @@ -839,17 +1102,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "basequantitykind": if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) @@ -857,17 +1119,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("baseQuantityKind"u8); - - if(value is IEnumerable objectListBaseQuantityKind) + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) { + writer.WriteStartArray("baseQuantityKind"u8); + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) { writer.WriteOrderedItem(baseQuantityKindItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "baseunit": if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) @@ -875,17 +1136,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("baseUnit"u8); - - if(value is IEnumerable objectListBaseUnit) + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) { + writer.WriteStartArray("baseUnit"u8); + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(baseUnitItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -911,17 +1171,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("constant"u8); - - if(value is IEnumerable objectListConstant) + if (value is IEnumerable objectListConstant && objectListConstant.Any()) { + writer.WriteStartArray("constant"u8); + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(constantItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definedcategory": if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) @@ -929,17 +1188,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definedCategory"u8); - - if(value is IEnumerable objectListDefinedCategory) + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) { + writer.WriteStartArray("definedCategory"u8); + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definedCategoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "definition": if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) @@ -947,17 +1205,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -965,17 +1222,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -983,17 +1239,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "filetype": if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) @@ -1001,17 +1256,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("fileType"u8); - - if(value is IEnumerable objectListFileType) + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { + writer.WriteStartArray("fileType"u8); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(fileTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "glossary": if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) @@ -1019,17 +1273,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("glossary"u8); - - if(value is IEnumerable objectListGlossary) + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) { + writer.WriteStartArray("glossary"u8); + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(glossaryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -1037,17 +1290,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -1127,17 +1379,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("parameterType"u8); - - if(value is IEnumerable objectListParameterType) + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { + writer.WriteStartArray("parameterType"u8); + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(parameterTypeItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "referencesource": if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) @@ -1145,17 +1396,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("referenceSource"u8); - - if(value is IEnumerable objectListReferenceSource) + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) { + writer.WriteStartArray("referenceSource"u8); + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(referenceSourceItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "requiredrdl": if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) @@ -1199,17 +1449,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("rule"u8); - - if(value is IEnumerable objectListRule) + if (value is IEnumerable objectListRule && objectListRule.Any()) { + writer.WriteStartArray("rule"u8); + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(ruleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "scale": if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) @@ -1217,17 +1466,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("scale"u8); - - if(value is IEnumerable objectListScale) + if (value is IEnumerable objectListScale && objectListScale.Any()) { + writer.WriteStartArray("scale"u8); + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(scaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shortname": if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) @@ -1271,17 +1519,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("unit"u8); - - if(value is IEnumerable objectListUnit) + if (value is IEnumerable objectListUnit && objectListUnit.Any()) { + writer.WriteStartArray("unit"u8); + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(unitItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "unitprefix": if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) @@ -1289,17 +1536,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("unitPrefix"u8); - - if(value is IEnumerable objectListUnitPrefix) + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) { + writer.WriteStartArray("unitPrefix"u8); + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(unitPrefixItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 4bfe39b12..89a3d3817 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,23 +85,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -124,23 +132,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -176,23 +192,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (solution.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -324,17 +348,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -342,17 +365,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index eac937655..893c7dc2b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,47 +77,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -125,14 +141,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -145,65 +165,89 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -213,14 +257,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); - writer.WriteEndArray(); + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -233,65 +281,89 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -301,14 +373,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); - writer.WriteEndArray(); + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -334,65 +410,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -402,14 +501,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - writer.WriteStartArray("possibleScale"u8); - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + if (specializedQuantityKind.PossibleScale.Count > 0) { - writer.WriteStringValue(possibleScaleItem); - } + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -467,17 +570,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -485,17 +587,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -539,17 +640,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -557,17 +657,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -575,17 +674,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "general": if(!AllowedVersionsPerProperty["general"].Contains(requestedVersion)) @@ -611,17 +709,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -701,17 +798,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("possibleScale"u8); - - if(value is IEnumerable objectListPossibleScale) + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { + writer.WriteStartArray("possibleScale"u8); + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(possibleScaleItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "quantitydimensionsymbol": if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 140d52943..3cf7db465 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,70 +77,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -148,113 +176,157 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); - writer.WriteEndArray(); + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - writer.WriteStartArray("settings"u8); - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Settings.Count > 0) { - writer.WriteStringValue(settingsItem); - } + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); - writer.WriteEndArray(); + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -262,47 +334,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); - writer.WriteEndArray(); + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - writer.WriteStartArray("settings"u8); - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Settings.Count > 0) { - writer.WriteStringValue(settingsItem); - } + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); - writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -318,70 +406,97 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("goal"u8); - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Goal.Count > 0) { - writer.WriteStringValue(goalItem); - } + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -389,47 +504,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - writer.WriteStartArray("requirement"u8); - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Requirement.Count > 0) { - writer.WriteStringValue(requirementItem); - } + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - writer.WriteStartArray("settings"u8); - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.Settings.Count > 0) { - writer.WriteStringValue(settingsItem); - } + writer.WriteStartArray("settings"u8); - writer.WriteEndArray(); + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); - writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMap.ValueGroup.Count > 0) { - writer.WriteStringValue(valueGroupItem); - } + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -477,17 +608,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -495,17 +625,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -531,17 +660,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -549,17 +677,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -567,17 +694,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "goal": if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) @@ -585,17 +711,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("goal"u8); - - if(value is IEnumerable objectListGoal) + if (value is IEnumerable objectListGoal && objectListGoal.Any()) { + writer.WriteStartArray("goal"u8); + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(goalItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -603,17 +728,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -675,17 +799,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("requirement"u8); - - if(value is IEnumerable objectListRequirement) + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) { + writer.WriteStartArray("requirement"u8); + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(requirementItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "revisionnumber": if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) @@ -711,17 +834,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("settings"u8); - - if(value is IEnumerable objectListSettings) + if (value is IEnumerable objectListSettings && objectListSettings.Any()) { + writer.WriteStartArray("settings"u8); + foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(settingsItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "shortname": if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) @@ -747,17 +869,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("stakeholderValue"u8); - - if(value is IEnumerable objectListStakeholderValue) + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { + writer.WriteStartArray("stakeholderValue"u8); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(stakeholderValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) @@ -783,17 +904,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("valueGroup"u8); - - if(value is IEnumerable objectListValueGroup) + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) { + writer.WriteStartArray("valueGroup"u8); + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(valueGroupItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 9a0ecc249..83c0a93ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -79,23 +79,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -141,23 +149,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -216,23 +232,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -339,17 +363,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -357,17 +380,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "goaltovaluegrouprelationship": if(!AllowedVersionsPerProperty["goalToValueGroupRelationship"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 4e34a4882..84976b8a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,61 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -143,73 +167,101 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -221,14 +273,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); - writer.WriteEndArray(); + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); @@ -246,61 +302,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -312,14 +391,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - writer.WriteStartArray("stakeholderValue"u8); - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + if (stakeholder.StakeholderValue.Count > 0) { - writer.WriteStringValue(stakeholderValueItem); - } + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); @@ -369,17 +452,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -387,17 +469,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -423,17 +504,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -441,17 +521,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -459,17 +538,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -477,17 +555,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -585,17 +662,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("stakeholderValue"u8); - - if(value is IEnumerable objectListStakeholderValue) + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { + writer.WriteStartArray("stakeholderValue"u8); + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(stakeholderValueItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "thingpreference": if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 5279e8a3d..6382cf966 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,61 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -146,61 +170,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -228,61 +276,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (stakeholderValue.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -342,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -360,17 +430,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -396,17 +465,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -414,17 +482,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -432,17 +499,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -450,17 +516,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index edd1133a9..070a98147 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -85,37 +85,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(telephoneNumber.RevisionNumber); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - foreach(var vcardTypeItem in telephoneNumber.VcardType) + if (telephoneNumber.VcardType.Count > 0) { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + writer.WriteStartArray("vcardType"u8); - writer.WriteEndArray(); + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -125,37 +137,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(telephoneNumber.RevisionNumber); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - foreach(var vcardTypeItem in telephoneNumber.VcardType) + if (telephoneNumber.VcardType.Count > 0) { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -167,14 +191,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(telephoneNumber.ThingPreference); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - foreach(var vcardTypeItem in telephoneNumber.VcardType) + if (telephoneNumber.VcardType.Count > 0) { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.3.0": @@ -192,23 +220,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (telephoneNumber.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -220,14 +256,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(telephoneNumber.ThingPreference); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - writer.WriteStartArray("vcardType"u8); - foreach(var vcardTypeItem in telephoneNumber.VcardType) + if (telephoneNumber.VcardType.Count > 0) { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; default: @@ -293,17 +333,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -311,17 +350,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) @@ -419,17 +457,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("vcardType"u8); - - if(value is IEnumerable objectListVcardType) + if (value is IEnumerable objectListVcardType && objectListVcardType.Any()) { - foreach(var vcardTypeItem in objectListVcardType) + writer.WriteStartArray("vcardType"u8); + + foreach (var vcardTypeItem in objectListVcardType) { writer.WriteStringValue(((VcardTelephoneNumberKind)vcardTypeItem).ToString()); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the TelephoneNumber"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 00c4ad377..d48d6fe6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,34 +77,46 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + if (term.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + if (term.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (term.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -119,52 +131,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + if (term.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + if (term.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (term.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -181,52 +213,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + if (term.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + if (term.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (term.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -256,52 +308,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + if (term.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + if (term.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (term.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (term.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -363,17 +434,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -399,17 +469,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -417,17 +486,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -435,17 +503,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -453,17 +520,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index daafd885e..ddb1be614 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -130,61 +146,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -203,61 +243,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -289,61 +353,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (textParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +597,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index 132af6d3b..70e59fd3e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,14 +77,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + if (textualNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -92,23 +96,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -127,14 +139,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); - writer.WriteStartArray("category"u8); - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + if (textualNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -142,23 +158,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -190,14 +214,17 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + if (textualNote.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -205,23 +232,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (textualNote.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -285,17 +320,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -357,17 +391,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -375,17 +408,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index aca7ec451..3b7d7173d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,43 +77,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -130,61 +146,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -203,61 +243,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -289,61 +353,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (timeOfDayParameterType.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -407,17 +494,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -425,17 +511,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -461,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -479,17 +563,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -497,17 +580,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -515,17 +597,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 5e29c196b..98f7e5eef 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitFactor.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "exponent": if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 9bed99333..46c9932fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,36 +77,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -121,54 +133,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -185,54 +217,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -262,54 +314,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); - writer.WriteEndArray(); + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (unitPrefix.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -371,17 +442,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -425,17 +495,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -443,17 +512,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -461,17 +529,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -479,17 +546,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 017bf8548..95403c531 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -92,23 +92,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -125,23 +133,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -171,23 +187,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userPreference.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -265,17 +289,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -283,17 +306,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index e7d7b52e7..cbbd33c88 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -100,37 +100,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Rule); writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -155,37 +167,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Rule); writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); + + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -212,14 +236,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); - writer.WriteEndArray(); + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + } break; case "1.3.0": @@ -237,23 +265,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("executedOn"u8); @@ -280,14 +316,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - writer.WriteStartArray("violation"u8); - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + if (userRuleVerification.Violation.Count > 0) { - writer.WriteStringValue(violationItem); - } + writer.WriteStartArray("violation"u8); - writer.WriteEndArray(); + foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(violationItem); + } + + writer.WriteEndArray(); + } break; default: @@ -353,17 +393,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -371,17 +410,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "executedon": if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) @@ -533,17 +571,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("violation"u8); - - if(value is IEnumerable objectListViolation) + if (value is IEnumerable objectListViolation && objectListViolation.Any()) { + writer.WriteStartArray("violation"u8); + foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(violationItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the UserRuleVerification"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 9841c2313..e17e14787 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -77,61 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -146,61 +170,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -228,61 +276,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Alias.Count > 0) { - writer.WriteStringValue(aliasItem); - } + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("category"u8); - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Category.Count > 0) { - writer.WriteStringValue(categoryItem); - } + writer.WriteStartArray("category"u8); - writer.WriteEndArray(); + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - writer.WriteStartArray("definition"u8); - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.Definition.Count > 0) { - writer.WriteStringValue(definitionItem); - } + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedDomain.Count > 0) { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.ExcludedPerson.Count > 0) { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); + writer.WriteEndArray(); + } - writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + if (valueGroup.HyperLink.Count > 0) { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + } writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -342,17 +413,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("alias"u8); - - if(value is IEnumerable objectListAlias) + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { + writer.WriteStartArray("alias"u8); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(aliasItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "category": if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) @@ -360,17 +430,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("category"u8); - - if(value is IEnumerable objectListCategory) + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { + writer.WriteStartArray("category"u8); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(categoryItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "classkind": if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) @@ -396,17 +465,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("definition"u8); - - if(value is IEnumerable objectListDefinition) + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { + writer.WriteStartArray("definition"u8); + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(definitionItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludeddomain": if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) @@ -414,17 +482,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedDomain"u8); - - if(value is IEnumerable objectListExcludedDomain) + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { + writer.WriteStartArray("excludedDomain"u8); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedDomainItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "excludedperson": if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) @@ -432,17 +499,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("excludedPerson"u8); - - if(value is IEnumerable objectListExcludedPerson) + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { + writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(excludedPersonItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "hyperlink": if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) @@ -450,17 +516,16 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } - writer.WriteStartArray("hyperLink"u8); - - if(value is IEnumerable objectListHyperLink) + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { + writer.WriteStartArray("hyperLink"u8); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) { writer.WriteStringValue(hyperLinkItem); } + writer.WriteEndArray(); } - - writer.WriteEndArray(); break; case "iid": if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) diff --git a/CDP4JsonSerializer/Helper/SerializerHelper.cs b/CDP4JsonSerializer/Helper/SerializerHelper.cs index 1989dab59..5e34f6dec 100644 --- a/CDP4JsonSerializer/Helper/SerializerHelper.cs +++ b/CDP4JsonSerializer/Helper/SerializerHelper.cs @@ -111,6 +111,9 @@ public static void WriteOrderedItem(this Utf8JsonWriter writer, OrderedItem orde case int intValue: writer.WriteNumberValue(intValue); break; + case long longValue: + writer.WriteNumberValue(longValue); + break; case double doubleValue: writer.WriteNumberValue(doubleValue); break; @@ -141,7 +144,7 @@ public static IEnumerable ToOrderedItemCollection(this JsonElement object valueToAssign = valueKind switch { JsonValueKind.String => valueProp.GetString(), - JsonValueKind.Number => valueProp.GetInt64(), + JsonValueKind.Number => valueProp.GetInt32(), _ => null }; diff --git a/pre-release.bat b/pre-release.bat index 512ad2715..fdc4863f8 100644 --- a/pre-release.bat +++ b/pre-release.bat @@ -44,7 +44,7 @@ ECHO. for %%f in (%~dp0PreReleaseBuilds\*.nupkg) do ( (Echo "%%f" | FIND /I "symbols" 1>NUL) || ( echo Pushing %%f - dotnet nuget push "%%f" --source https://nuget.pkg.github.com/RHEAGROUP/index.json -k %apikey% + echo dotnet nuget push "%%f" --source https://nuget.pkg.github.com/RHEAGROUP/index.json -k %apikey% ) ) From 10cfdfcd9ec3d5fc18557f5e505870035006f164 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Tue, 5 Nov 2024 14:28:29 +0100 Subject: [PATCH 19/34] Finetuning --- .../ActionItemResolver.cs | 3 + .../ActualFiniteStateListResolver.cs | 3 + .../ActualFiniteStateResolver.cs | 3 + .../AutoGenDtoDeserializer/AliasResolver.cs | 3 + .../AndExpressionResolver.cs | 3 + .../ApprovalResolver.cs | 3 + .../ArrayParameterTypeResolver.cs | 3 + .../BinaryNoteResolver.cs | 3 + .../BinaryRelationshipResolver.cs | 3 + .../BinaryRelationshipRuleResolver.cs | 3 + .../AutoGenDtoDeserializer/BookResolver.cs | 3 + .../BooleanParameterTypeResolver.cs | 3 + .../AutoGenDtoDeserializer/BoundsResolver.cs | 3 + .../BuiltInRuleVerificationResolver.cs | 3 + .../CategoryResolver.cs | 3 + .../ChangeProposalResolver.cs | 3 + .../ChangeRequestResolver.cs | 3 + .../CitationResolver.cs | 3 + .../AutoGenDtoDeserializer/ColorResolver.cs | 3 + .../CommonFileStoreResolver.cs | 3 + .../CompoundParameterTypeResolver.cs | 3 + .../ConstantResolver.cs | 19 +- .../ContractChangeNoticeResolver.cs | 3 + .../CyclicRatioScaleResolver.cs | 3 + .../DateParameterTypeResolver.cs | 3 + .../DateTimeParameterTypeResolver.cs | 3 + .../DecompositionRuleResolver.cs | 3 + .../DefinitionResolver.cs | 3 + ...ependentParameterTypeAssignmentResolver.cs | 3 + .../DerivedQuantityKindResolver.cs | 3 + .../DerivedUnitResolver.cs | 3 + .../DiagramCanvasResolver.cs | 3 + .../DiagramEdgeResolver.cs | 3 + .../DiagramObjectResolver.cs | 3 + .../DomainFileStoreResolver.cs | 3 + .../DomainOfExpertiseGroupResolver.cs | 3 + .../DomainOfExpertiseResolver.cs | 3 + .../ElementDefinitionResolver.cs | 3 + .../ElementUsageResolver.cs | 3 + .../EmailAddressResolver.cs | 3 + ...ineeringModelDataDiscussionItemResolver.cs | 3 + .../EngineeringModelDataNoteResolver.cs | 3 + .../EngineeringModelResolver.cs | 3 + .../EngineeringModelSetupResolver.cs | 3 + .../EnumerationParameterTypeResolver.cs | 3 + .../EnumerationValueDefinitionResolver.cs | 3 + .../ExclusiveOrExpressionResolver.cs | 3 + .../ExternalIdentifierMapResolver.cs | 3 + .../AutoGenDtoDeserializer/FileResolver.cs | 3 + .../FileRevisionResolver.cs | 3 + .../FileTypeResolver.cs | 3 + .../AutoGenDtoDeserializer/FolderResolver.cs | 3 + .../GlossaryResolver.cs | 3 + .../AutoGenDtoDeserializer/GoalResolver.cs | 3 + .../HyperLinkResolver.cs | 3 + .../IdCorrespondenceResolver.cs | 3 + ...ependentParameterTypeAssignmentResolver.cs | 3 + .../IntervalScaleResolver.cs | 3 + .../IterationResolver.cs | 3 + .../IterationSetupResolver.cs | 3 + .../LinearConversionUnitResolver.cs | 3 + .../LogEntryChangelogItemResolver.cs | 3 + .../LogarithmicScaleResolver.cs | 3 + .../MappingToReferenceScaleResolver.cs | 3 + .../ModelLogEntryResolver.cs | 3 + .../ModelReferenceDataLibraryResolver.cs | 3 + .../ModellingThingReferenceResolver.cs | 3 + .../MultiRelationshipResolver.cs | 3 + .../MultiRelationshipRuleResolver.cs | 3 + .../NaturalLanguageResolver.cs | 3 + .../NestedElementResolver.cs | 3 + .../NestedParameterResolver.cs | 3 + .../NotExpressionResolver.cs | 3 + .../AutoGenDtoDeserializer/OptionResolver.cs | 3 + .../OrExpressionResolver.cs | 3 + .../OrdinalScaleResolver.cs | 3 + .../OrganizationResolver.cs | 3 + .../OrganizationalParticipantResolver.cs | 3 + .../OwnedStyleResolver.cs | 3 + .../AutoGenDtoDeserializer/PageResolver.cs | 3 + .../ParameterGroupResolver.cs | 3 + .../ParameterOverrideResolver.cs | 3 + .../ParameterOverrideValueSetResolver.cs | 82 ++- .../ParameterResolver.cs | 3 + .../ParameterSubscriptionResolver.cs | 3 + .../ParameterSubscriptionValueSetResolver.cs | 19 +- .../ParameterTypeComponentResolver.cs | 3 + .../ParameterValueSetResolver.cs | 83 ++- .../ParameterizedCategoryRuleResolver.cs | 3 + .../ParametricConstraintResolver.cs | 3 + .../ParticipantPermissionResolver.cs | 3 + .../ParticipantResolver.cs | 3 + .../ParticipantRoleResolver.cs | 3 + .../PersonPermissionResolver.cs | 3 + .../AutoGenDtoDeserializer/PersonResolver.cs | 3 + .../PersonRoleResolver.cs | 3 + .../AutoGenDtoDeserializer/PointResolver.cs | 3 + .../PossibleFiniteStateListResolver.cs | 3 + .../PossibleFiniteStateResolver.cs | 3 + .../PrefixedUnitResolver.cs | 3 + .../PublicationResolver.cs | 3 + .../QuantityKindFactorResolver.cs | 3 + .../RatioScaleResolver.cs | 3 + .../ReferenceSourceResolver.cs | 3 + .../ReferencerRuleResolver.cs | 3 + .../RelationalExpressionResolver.cs | 19 +- .../RelationshipParameterValueResolver.cs | 19 +- .../RequestForDeviationResolver.cs | 3 + .../RequestForWaiverResolver.cs | 3 + .../RequirementResolver.cs | 3 + ...irementsContainerParameterValueResolver.cs | 19 +- .../RequirementsGroupResolver.cs | 3 + .../RequirementsSpecificationResolver.cs | 3 + .../ReviewItemDiscrepancyResolver.cs | 3 + .../RuleVerificationListResolver.cs | 3 + .../RuleViolationResolver.cs | 3 + .../SampledFunctionParameterTypeResolver.cs | 19 +- .../ScaleReferenceQuantityValueResolver.cs | 3 + .../ScaleValueDefinitionResolver.cs | 3 + .../AutoGenDtoDeserializer/SectionResolver.cs | 3 + .../SharedStyleResolver.cs | 3 + .../SimpleParameterValueResolver.cs | 19 +- .../SimpleQuantityKindResolver.cs | 3 + .../SimpleUnitResolver.cs | 3 + .../SiteDirectoryDataAnnotationResolver.cs | 3 + ...SiteDirectoryDataDiscussionItemResolver.cs | 3 + .../SiteDirectoryResolver.cs | 3 + .../SiteDirectoryThingReferenceResolver.cs | 3 + .../SiteLogEntryResolver.cs | 3 + .../SiteReferenceDataLibraryResolver.cs | 3 + .../SolutionResolver.cs | 3 + .../SpecializedQuantityKindResolver.cs | 3 + .../StakeHolderValueMapResolver.cs | 3 + .../StakeHolderValueMapSettingsResolver.cs | 3 + .../StakeholderResolver.cs | 3 + .../StakeholderValueResolver.cs | 3 + .../TelephoneNumberResolver.cs | 3 + .../AutoGenDtoDeserializer/TermResolver.cs | 3 + .../TextParameterTypeResolver.cs | 3 + .../TextualNoteResolver.cs | 3 + .../TimeOfDayParameterTypeResolver.cs | 3 + .../UnitFactorResolver.cs | 3 + .../UnitPrefixResolver.cs | 3 + .../UserPreferenceResolver.cs | 3 + .../UserRuleVerificationResolver.cs | 3 + .../ValueGroupResolver.cs | 3 + .../ActionItemSerializer.cs | 165 +++--- .../ActualFiniteStateListSerializer.cs | 137 +++-- .../ActualFiniteStateSerializer.cs | 79 +-- .../AutoGenDtoSerializer/AliasSerializer.cs | 50 +- .../AndExpressionSerializer.cs | 79 +-- .../ApprovalSerializer.cs | 50 +- .../ArrayParameterTypeSerializer.cs | 224 ++++---- .../BinaryNoteSerializer.cs | 73 ++- .../BinaryRelationshipRuleSerializer.cs | 137 +++-- .../BinaryRelationshipSerializer.cs | 102 ++-- .../AutoGenDtoSerializer/BookSerializer.cs | 96 ++-- .../BooleanParameterTypeSerializer.cs | 166 +++--- .../AutoGenDtoSerializer/BoundsSerializer.cs | 50 +- .../BuiltInRuleVerificationSerializer.cs | 79 +-- .../CategorySerializer.cs | 195 ++++--- .../ChangeProposalSerializer.cs | 165 +++--- .../ChangeRequestSerializer.cs | 165 +++--- .../CitationSerializer.cs | 50 +- .../AutoGenDtoSerializer/ColorSerializer.cs | 50 +- .../CommonFileStoreSerializer.cs | 108 ++-- .../CompoundParameterTypeSerializer.cs | 195 ++++--- .../ConstantSerializer.cs | 166 +++--- .../ContractChangeNoticeSerializer.cs | 165 +++--- .../CyclicRatioScaleSerializer.cs | 195 ++++--- .../DateParameterTypeSerializer.cs | 166 +++--- .../DateTimeParameterTypeSerializer.cs | 166 +++--- .../DecompositionRuleSerializer.cs | 166 +++--- .../DefinitionSerializer.cs | 137 +++-- ...endentParameterTypeAssignmentSerializer.cs | 38 +- .../DerivedQuantityKindSerializer.cs | 224 ++++---- .../DerivedUnitSerializer.cs | 166 +++--- .../DiagramCanvasSerializer.cs | 96 ++-- .../DiagramEdgeSerializer.cs | 142 +++-- .../DiagramObjectSerializer.cs | 119 +++-- .../DomainFileStoreSerializer.cs | 108 ++-- .../DomainOfExpertiseGroupSerializer.cs | 166 +++--- .../DomainOfExpertiseSerializer.cs | 166 +++--- .../ElementDefinitionSerializer.cs | 299 ++++++----- .../ElementUsageSerializer.cs | 224 ++++---- .../EmailAddressSerializer.cs | 50 +- ...eeringModelDataDiscussionItemSerializer.cs | 50 +- .../EngineeringModelDataNoteSerializer.cs | 96 ++-- .../EngineeringModelSerializer.cs | 206 ++++--- .../EngineeringModelSetupSerializer.cs | 270 ++++++---- .../EnumerationParameterTypeSerializer.cs | 195 ++++--- .../EnumerationValueDefinitionSerializer.cs | 137 +++-- .../ExclusiveOrExpressionSerializer.cs | 79 +-- .../ExternalIdentifierMapSerializer.cs | 79 +-- .../FileRevisionSerializer.cs | 79 +-- .../AutoGenDtoSerializer/FileSerializer.cs | 108 ++-- .../FileTypeSerializer.cs | 166 +++--- .../AutoGenDtoSerializer/FolderSerializer.cs | 50 +- .../GlossarySerializer.cs | 195 ++++--- .../AutoGenDtoSerializer/GoalSerializer.cs | 142 +++-- .../HyperLinkSerializer.cs | 50 +- .../IdCorrespondenceSerializer.cs | 50 +- ...endentParameterTypeAssignmentSerializer.cs | 38 +- .../IntervalScaleSerializer.cs | 195 ++++--- .../IterationSerializer.cs | 501 +++++++++++------- .../IterationSetupSerializer.cs | 50 +- .../LinearConversionUnitSerializer.cs | 137 +++-- .../LogEntryChangelogItemSerializer.cs | 55 +- .../LogarithmicScaleSerializer.cs | 224 ++++---- .../MappingToReferenceScaleSerializer.cs | 50 +- .../ModelLogEntrySerializer.cs | 154 +++--- .../ModelReferenceDataLibrarySerializer.cs | 485 ++++++++++------- .../ModellingThingReferenceSerializer.cs | 50 +- .../MultiRelationshipRuleSerializer.cs | 166 +++--- .../MultiRelationshipSerializer.cs | 131 +++-- .../NaturalLanguageSerializer.cs | 50 +- .../NestedElementSerializer.cs | 108 ++-- .../NestedParameterSerializer.cs | 50 +- .../NotExpressionSerializer.cs | 50 +- .../AutoGenDtoSerializer/OptionSerializer.cs | 195 ++++--- .../OrExpressionSerializer.cs | 79 +-- .../OrdinalScaleSerializer.cs | 195 ++++--- .../OrganizationSerializer.cs | 50 +- .../OrganizationalParticipantSerializer.cs | 38 +- .../OwnedStyleSerializer.cs | 73 ++- .../AutoGenDtoSerializer/PageSerializer.cs | 96 ++-- .../ParameterGroupSerializer.cs | 50 +- .../ParameterOverrideSerializer.cs | 108 ++-- .../ParameterOverrideValueSetSerializer.cs | 50 +- .../ParameterSerializer.cs | 108 ++-- .../ParameterSubscriptionSerializer.cs | 79 +-- ...ParameterSubscriptionValueSetSerializer.cs | 50 +- .../ParameterTypeComponentSerializer.cs | 50 +- .../ParameterValueSetSerializer.cs | 50 +- .../ParameterizedCategoryRuleSerializer.cs | 166 +++--- .../ParametricConstraintSerializer.cs | 79 +-- .../ParticipantPermissionSerializer.cs | 50 +- .../ParticipantRoleSerializer.cs | 166 +++--- .../ParticipantSerializer.cs | 79 +-- .../PersonPermissionSerializer.cs | 50 +- .../PersonRoleSerializer.cs | 166 +++--- .../AutoGenDtoSerializer/PersonSerializer.cs | 137 +++-- .../AutoGenDtoSerializer/PointSerializer.cs | 50 +- .../PossibleFiniteStateListSerializer.cs | 195 ++++--- .../PossibleFiniteStateSerializer.cs | 137 +++-- .../PrefixedUnitSerializer.cs | 137 +++-- .../PublicationSerializer.cs | 108 ++-- .../QuantityKindFactorSerializer.cs | 50 +- .../RatioScaleSerializer.cs | 195 ++++--- .../ReferenceSourceSerializer.cs | 166 +++--- .../ReferencerRuleSerializer.cs | 166 +++--- .../RelationalExpressionSerializer.cs | 50 +- .../RelationshipParameterValueSerializer.cs | 50 +- .../RequestForDeviationSerializer.cs | 165 +++--- .../RequestForWaiverSerializer.cs | 165 +++--- .../RequirementSerializer.cs | 224 ++++---- ...ementsContainerParameterValueSerializer.cs | 50 +- .../RequirementsGroupSerializer.cs | 212 +++++--- .../RequirementsSpecificationSerializer.cs | 241 +++++---- .../ReviewItemDiscrepancySerializer.cs | 188 ++++--- .../RuleVerificationListSerializer.cs | 166 +++--- .../RuleViolationSerializer.cs | 79 +-- .../SampledFunctionParameterTypeSerializer.cs | 140 +++-- .../ScaleReferenceQuantityValueSerializer.cs | 50 +- .../ScaleValueDefinitionSerializer.cs | 137 +++-- .../AutoGenDtoSerializer/SectionSerializer.cs | 96 ++-- .../SharedStyleSerializer.cs | 73 ++- .../SimpleParameterValueSerializer.cs | 50 +- .../SimpleQuantityKindSerializer.cs | 195 ++++--- .../SimpleUnitSerializer.cs | 137 +++-- .../SiteDirectoryDataAnnotationSerializer.cs | 96 ++-- ...teDirectoryDataDiscussionItemSerializer.cs | 50 +- .../SiteDirectorySerializer.cs | 363 ++++++++----- .../SiteDirectoryThingReferenceSerializer.cs | 50 +- .../SiteLogEntrySerializer.cs | 154 +++--- .../SiteReferenceDataLibrarySerializer.cs | 485 ++++++++++------- .../SolutionSerializer.cs | 50 +- .../SpecializedQuantityKindSerializer.cs | 195 ++++--- .../StakeHolderValueMapSerializer.cs | 257 +++++---- .../StakeHolderValueMapSettingsSerializer.cs | 50 +- .../StakeholderSerializer.cs | 165 +++--- .../StakeholderValueSerializer.cs | 142 +++-- .../TelephoneNumberSerializer.cs | 79 +-- .../AutoGenDtoSerializer/TermSerializer.cs | 137 +++-- .../TextParameterTypeSerializer.cs | 166 +++--- .../TextualNoteSerializer.cs | 73 ++- .../TimeOfDayParameterTypeSerializer.cs | 166 +++--- .../UnitFactorSerializer.cs | 50 +- .../UnitPrefixSerializer.cs | 137 +++-- .../UserPreferenceSerializer.cs | 50 +- .../UserRuleVerificationSerializer.cs | 79 +-- .../ValueGroupSerializer.cs | 142 +++-- 292 files changed, 12170 insertions(+), 7331 deletions(-) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index c4c630f61..886d54a35 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index 5f599126e..3df83fcdf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index 97474b0d8..8e5616e1f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index bb0f859c3..a9d83dab8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index 51a6c7418..b17fe3a94 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index 1a8acf813..1378b5439 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index 7468710cc..8d8cb1a3c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index 84fd7954e..150164e5b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index b324a7a2d..350edb31d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index ee15b3b01..89539ffe2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index ec7c73f59..4c2240528 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index 3adccd1fb..a1ccc896e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index 2ab0b5091..064b09dc6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index 98ff206db..83eb3dbdf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index 136302465..45ad0f807 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index d7fd3c3d1..ec4313f4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index 65ee35157..81da64c3c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index aef860fc3..6cd195a75 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index ca61938e8..64f3c820a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index 0969d7170..cbabb3ccb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index 39482bbd2..7d46e2a25 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index 8b0bdcc64..0a6290ba7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -194,9 +197,23 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) constant.ThingPreference = thingPreferenceProperty.GetString(); } } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - constant.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + if(valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + constant.Value = new ValueArray(newValueArrayItems); + } + else + { + constant.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return constant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index 2e9024570..440dc5ea1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index 130ac64a6..5eb7acbbb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index 0d19d7dbf..1ad2f7457 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index 259457721..d3c3a6620 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index a179dc8eb..5ca9ea740 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 3dbfce7c4..23ee6d215 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index 6cba47589..e9c7e003e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index 90fecb3f7..29b993504 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index 4346800f7..89be5f946 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index 7ded4b613..2500cd181 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index dd993465d..eff757305 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index 4477d81ce..832cebd8f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index 1f173b3d1..c0aae96a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index 59571a59a..13f635805 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index e81c0408d..d25fec368 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index 5713aa4f6..a3a1186f2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index 56f20ecfe..84b8ff183 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index 7d7d3bea3..eecf1b006 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index 4a27537a5..fdf634937 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index 5c1508d82..96f218979 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index aeac88ff6..612285fbd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index 1ce062d0a..d4a42835d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index d3837abd6..82e9978ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index 5fa2053af..c3965c910 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index 1f8ab3861..808237cf3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index 04c37e0ff..af3557a53 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index c07ae429c..56606ebe4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index 183011498..84b0ed63e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 743c58341..7e2cff570 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index a15b5febc..7f7cdba90 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 0f233c960..1b6baf58d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index be107d3a5..9139e52c2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index 8b5405ded..f08292f97 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index bcbf34af9..8ea5d617f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index ad3bd6f91..e66252ef9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index 0dd94eb40..4101ad9c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index c98d0a973..e2dd7c61b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index 74109e6a8..439a668af 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index 5ec8444b6..0408618a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index 797969a52..c795f5d20 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index 8b3a5e2d6..6645e5c3a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index e9ccb89b0..0f7b7671a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index b094b4c33..3ad4b47e3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 30bd10fae..978be2fa5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index 0be75fb8f..3bcd0fcde 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index bb84b2ff0..28ee1e416 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index f416dd9eb..5631e7be2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index faf8c2fca..a01154c7b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index 267e809bc..f9cfec896 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index 2598bdb4f..c261de473 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index ced4ee8de..736d57d6b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index 37f545056..dd39926d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index a6c5e29a7..45a5bd143 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index 28e6d26b5..35ec33a77 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index 2212bddfd..8544a4a27 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index a477bc0d3..1480eb752 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index c4c58cb19..fa4a569a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index 8e660d4c1..802b3aab3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 464ab4ccd..06806abb8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index 581450bb9..e6ef2acc5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index 24b52b639..df4bee086 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -65,7 +68,20 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + if(computedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in computedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Computed = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + } } if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) @@ -83,13 +99,41 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.ExcludedPerson.Add(element.GetGuid()); } } + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + if(formulaProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in formulaProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Formula = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + } } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + if(manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) @@ -115,13 +159,41 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.ParameterValueSet = parameterValueSetProperty.GetGuid(); } } + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) { - parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + if(publishedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in publishedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Published = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + if(referenceProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in referenceProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Reference = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + } } if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index 8c6f0d9a5..57a1bb26b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index 7ed54fe41..babcc8d7a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index 07a280703..b0019a730 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -78,9 +81,23 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl parameterSubscriptionValueSet.ExcludedPerson.Add(element.GetGuid()); } } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + if(manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterSubscriptionValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index 8223b6a2f..ffef8aae8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index 045a68a19..856685cba 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -86,9 +89,23 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ActualState = actualStateProperty.GetGuid(); } } + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + if(computedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in computedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Computed = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + } } if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) @@ -106,13 +123,41 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ExcludedPerson.Add(element.GetGuid()); } } + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + if(formulaProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in formulaProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Formula = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + } } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + if(manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) @@ -126,13 +171,41 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); } } + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) { - parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + if(publishedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in publishedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Published = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + if(referenceProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in referenceProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Reference = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + } } if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index dd07a654d..dfe057d1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index 0a2167b1a..1f561b0ce 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index c2339f659..b9aa667df 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index ae2e97390..74f51f146 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index dc98a81ec..bb8ff8fc8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index 4319167f7..b07ec56eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index 286a55dd9..f1d7642ba 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index 41661b8bf..b5a8d0600 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index cbe6fc2ac..b4ee1a93c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index e512c0dcb..0095626d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index 11535ae6f..0d6650557 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index 839c14026..e75645efd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index d72f4da56..da21655f2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index 089263793..9643ed834 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 7cf7008c1..5e34f7b5d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index b32c08056..866134a1e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index fc0f56672..314f255e9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index ca549cad2..9b8f7786b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -138,9 +141,23 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso relationalExpression.ThingPreference = thingPreferenceProperty.GetString(); } } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationalExpression.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + if(valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + relationalExpression.Value = new ValueArray(newValueArrayItems); + } + else + { + relationalExpression.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return relationalExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index 65c5f9236..254b03fde 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -126,9 +129,23 @@ public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonEleme relationshipParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationshipParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + if(valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + relationshipParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + relationshipParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return relationshipParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index e3f87ec31..2db7e9a48 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index a56451c6b..85dbdb22d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index 2d7adbcde..af1bcb7ce 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index 4fbdf07aa..e70b398d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -126,9 +129,23 @@ public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject( requirementsContainerParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + if(valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + requirementsContainerParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return requirementsContainerParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index 1439abe7f..9bb9827c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index c6cb5b0c4..d5ef4da2e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index 163e50852..39d475e53 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index 2d970f525..7031f4a51 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index 45a79e1df..fd9f030fe 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index 946660f7c..4a77d6f6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -132,9 +135,23 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { sampledFunctionParameterType.IndependentParameterType.AddRange(independentParameterTypeProperty.ToOrderedItemCollection()); } + if (jsonElement.TryGetProperty("interpolationPeriod"u8, out var interpolationPeriodProperty)) { - sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(interpolationPeriodProperty.GetString()); + if(interpolationPeriodProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in interpolationPeriodProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + sampledFunctionParameterType.InterpolationPeriod = new ValueArray(newValueArrayItems); + } + else + { + sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(interpolationPeriodProperty.GetString()); + } } if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index 4b915e1f5..76b791ff5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index 819ab270f..1b02a134e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index 9fc4e315c..abbd3dc14 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index cfa19318a..413764f91 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index fa8f3b82c..b4969c27f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// @@ -126,9 +129,23 @@ public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jso simpleParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - simpleParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + if(valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + simpleParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + simpleParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return simpleParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index d3cf8a6e2..e63896767 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index 2e4812866..3f72f5ca8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index 68d422c8b..b3aa780c6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 459029ada..9c98ce00e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index 6c3350b55..27c9db3a0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index 11ccc900c..f40b568be 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index a3c5db285..4f8550a33 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index dd212ecb4..81e490656 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index 9d427ee8a..db7714f65 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index 8c7076c26..fa950d2ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index 5795d07a2..589efb71e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index 9863c5486..581771269 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index 2a4191a5a..c77fa91f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index 88d7c6a47..9070fe184 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 95b744ffe..15cf8e744 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index ed17540c9..fd8dc64c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index ae9fbb9d1..0e258bb60 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index 14391575e..dbe622619 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index 1cea57539..cdf6a4a41 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index 217ebd135..bd5290b29 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index 7871cf4e8..06a2d3b5e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index 20bea1856..293e3e25e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index d5edbfa43..8924818aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index b7cb379dd..a95c3a155 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -28,8 +28,11 @@ namespace CDP4JsonSerializer { + using System.Collections.Generic; using System.Text.Json; + using CDP4Common.Types; + using NLog; /// diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 40fc2cb56..f3b101fa1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); - if (actionItem.ApprovedBy.Count > 0) - { + //if (actionItem.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -90,13 +94,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - if (actionItem.Category.Count > 0) - { + //if (actionItem.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) @@ -105,7 +109,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.Discussion.Count > 0) - { + //if (actionItem.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -139,13 +143,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.ExcludedDomain.Count > 0) - { + //if (actionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -154,11 +158,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actionItem.ExcludedPerson.Count > 0) - { + //if (actionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -167,7 +171,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (actionItem.RelatedThing.Count > 0) - { + //if (actionItem.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -198,15 +202,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - if (actionItem.SourceAnnotation.Count > 0) - { + //if (actionItem.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -215,7 +219,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -227,8 +231,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); - if (actionItem.ApprovedBy.Count > 0) - { + //if (actionItem.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -237,13 +241,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - if (actionItem.Category.Count > 0) - { + //if (actionItem.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) @@ -252,7 +256,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.Discussion.Count > 0) - { + //if (actionItem.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -286,13 +290,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.ExcludedDomain.Count > 0) - { + //if (actionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -301,11 +305,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actionItem.ExcludedPerson.Count > 0) - { + //if (actionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -314,7 +318,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -335,8 +339,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (actionItem.RelatedThing.Count > 0) - { + //if (actionItem.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -345,15 +349,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - if (actionItem.SourceAnnotation.Count > 0) - { + //if (actionItem.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -362,7 +366,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (actionItem.ApprovedBy.Count > 0) - { + //if (actionItem.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -396,13 +400,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); - if (actionItem.Category.Count > 0) - { + //if (actionItem.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) @@ -411,7 +415,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -435,8 +439,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.Discussion.Count > 0) - { + //if (actionItem.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -445,13 +449,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); - if (actionItem.ExcludedDomain.Count > 0) - { + //if (actionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -460,11 +464,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actionItem.ExcludedPerson.Count > 0) - { + //if (actionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -473,7 +477,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -494,8 +498,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (actionItem.RelatedThing.Count > 0) - { + //if (actionItem.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -504,15 +508,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); - if (actionItem.SourceAnnotation.Count > 0) - { + //if (actionItem.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -521,7 +525,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -593,6 +597,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -628,6 +637,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -753,6 +767,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -788,6 +807,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -805,6 +829,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -912,6 +941,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -965,6 +999,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index d23dfcb90..e9e1ee8d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); - if (actualFiniteStateList.ActualState.Count > 0) - { + //if (actualFiniteStateList.ActualState.Count > 0) + //{ writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - if (actualFiniteStateList.ExcludeOption.Count > 0) - { + //if (actualFiniteStateList.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -103,15 +107,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - { + //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -128,8 +132,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); - if (actualFiniteStateList.ActualState.Count > 0) - { + //if (actualFiniteStateList.ActualState.Count > 0) + //{ writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -138,13 +142,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - if (actualFiniteStateList.ExcludedDomain.Count > 0) - { + //if (actualFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -153,11 +157,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludedPerson.Count > 0) - { + //if (actualFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludeOption.Count > 0) - { + //if (actualFiniteStateList.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -179,7 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - { + //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -206,8 +210,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); - if (actualFiniteStateList.ActualState.Count > 0) - { + //if (actualFiniteStateList.ActualState.Count > 0) + //{ writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -216,13 +220,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - if (actualFiniteStateList.ExcludedDomain.Count > 0) - { + //if (actualFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludedPerson.Count > 0) - { + //if (actualFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,11 +248,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludeOption.Count > 0) - { + //if (actualFiniteStateList.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -257,7 +261,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - { + //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) @@ -276,7 +280,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -296,8 +300,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (actualFiniteStateList.ActualState.Count > 0) - { + //if (actualFiniteStateList.ActualState.Count > 0) + //{ writer.WriteStartArray("actualState"u8); foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) @@ -306,13 +310,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); - if (actualFiniteStateList.ExcludedDomain.Count > 0) - { + //if (actualFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -321,11 +325,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludedPerson.Count > 0) - { + //if (actualFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -334,11 +338,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteStateList.ExcludeOption.Count > 0) - { + //if (actualFiniteStateList.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -347,7 +351,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -356,8 +360,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); - if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - { + //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) @@ -366,7 +370,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -418,6 +422,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListActualState && objectListActualState.Any()) { writer.WriteStartArray("actualState"u8); @@ -453,6 +462,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -470,6 +484,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -487,6 +506,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) { writer.WriteStartArray("excludeOption"u8); @@ -558,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) { writer.WriteStartArray("possibleFiniteStateList"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 6d5b914ab..677d21611 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -84,8 +88,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("kind"u8); writer.WriteStringValue(actualFiniteState.Kind.ToString()); - if (actualFiniteState.PossibleState.Count > 0) - { + //if (actualFiniteState.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) @@ -94,7 +98,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -104,8 +108,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - if (actualFiniteState.ExcludedDomain.Count > 0) - { + //if (actualFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -114,11 +118,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteState.ExcludedPerson.Count > 0) - { + //if (actualFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -127,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -136,8 +140,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actualFiniteState.PossibleState.Count > 0) - { + //if (actualFiniteState.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) @@ -146,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -156,8 +160,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - if (actualFiniteState.ExcludedDomain.Count > 0) - { + //if (actualFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteState.ExcludedPerson.Count > 0) - { + //if (actualFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -179,7 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actualFiniteState.PossibleState.Count > 0) - { + //if (actualFiniteState.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -221,8 +225,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); - if (actualFiniteState.ExcludedDomain.Count > 0) - { + //if (actualFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (actualFiniteState.ExcludedPerson.Count > 0) - { + //if (actualFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,7 +248,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -253,8 +257,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (actualFiniteState.PossibleState.Count > 0) - { + //if (actualFiniteState.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) @@ -263,7 +267,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -333,6 +337,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -350,6 +359,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -421,6 +435,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) { writer.WriteStartArray("possibleState"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 7745b7aad..9f11aae8c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - if (alias.ExcludedDomain.Count > 0) - { + //if (alias.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (alias.ExcludedPerson.Count > 0) - { + //if (alias.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - if (alias.ExcludedDomain.Count > 0) - { + //if (alias.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -150,11 +154,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (alias.ExcludedPerson.Count > 0) - { + //if (alias.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -163,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -196,8 +200,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); - if (alias.ExcludedDomain.Count > 0) - { + //if (alias.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (alias.ExcludedPerson.Count > 0) - { + //if (alias.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -219,7 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -315,6 +319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -332,6 +341,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 3b09ac6b7..d6231dc43 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -84,8 +88,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - if (andExpression.Term.Count > 0) - { + //if (andExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -94,7 +98,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -102,8 +106,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - if (andExpression.ExcludedDomain.Count > 0) - { + //if (andExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -112,11 +116,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (andExpression.ExcludedPerson.Count > 0) - { + //if (andExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -125,7 +129,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - if (andExpression.Term.Count > 0) - { + //if (andExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -152,8 +156,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - if (andExpression.ExcludedDomain.Count > 0) - { + //if (andExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -162,11 +166,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (andExpression.ExcludedPerson.Count > 0) - { + //if (andExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -175,7 +179,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -184,8 +188,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - if (andExpression.Term.Count > 0) - { + //if (andExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); @@ -215,8 +219,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); - if (andExpression.ExcludedDomain.Count > 0) - { + //if (andExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -225,11 +229,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (andExpression.ExcludedPerson.Count > 0) - { + //if (andExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -238,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -247,8 +251,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); - if (andExpression.Term.Count > 0) - { + //if (andExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -257,7 +261,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); @@ -325,6 +329,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -342,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -413,6 +427,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { writer.WriteStartArray("term"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 7ed2dd5fd..5be1c81a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -88,8 +92,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (approval.ExcludedDomain.Count > 0) - { + //if (approval.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -98,11 +102,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (approval.ExcludedPerson.Count > 0) - { + //if (approval.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -111,7 +115,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -137,8 +141,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (approval.ExcludedDomain.Count > 0) - { + //if (approval.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -147,11 +151,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (approval.ExcludedPerson.Count > 0) - { + //if (approval.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -160,7 +164,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -199,8 +203,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (approval.ExcludedDomain.Count > 0) - { + //if (approval.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (approval.ExcludedPerson.Count > 0) - { + //if (approval.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -372,6 +376,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -389,6 +398,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 2bfbc8afe..f56e6177a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); - if (arrayParameterType.Alias.Count > 0) - { + //if (arrayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Category.Count > 0) - { + //if (arrayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - if (arrayParameterType.Component.Count > 0) - { + //if (arrayParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Definition.Count > 0) - { + //if (arrayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Dimension.Count > 0) - { + //if (arrayParameterType.Dimension.Count > 0) + //{ writer.WriteStartArray("dimension"u8); foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.HyperLink.Count > 0) - { + //if (arrayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -177,8 +181,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); - if (arrayParameterType.Alias.Count > 0) - { + //if (arrayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -187,11 +191,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Category.Count > 0) - { + //if (arrayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -200,13 +204,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - if (arrayParameterType.Component.Count > 0) - { + //if (arrayParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -215,11 +219,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Definition.Count > 0) - { + //if (arrayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -228,11 +232,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Dimension.Count > 0) - { + //if (arrayParameterType.Dimension.Count > 0) + //{ writer.WriteStartArray("dimension"u8); foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) @@ -241,11 +245,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedDomain.Count > 0) - { + //if (arrayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedPerson.Count > 0) - { + //if (arrayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -267,11 +271,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.HyperLink.Count > 0) - { + //if (arrayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -280,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -304,8 +308,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); - if (arrayParameterType.Alias.Count > 0) - { + //if (arrayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Category.Count > 0) - { + //if (arrayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -327,13 +331,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - if (arrayParameterType.Component.Count > 0) - { + //if (arrayParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -342,11 +346,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Definition.Count > 0) - { + //if (arrayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -355,11 +359,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Dimension.Count > 0) - { + //if (arrayParameterType.Dimension.Count > 0) + //{ writer.WriteStartArray("dimension"u8); foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) @@ -368,11 +372,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedDomain.Count > 0) - { + //if (arrayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -381,11 +385,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedPerson.Count > 0) - { + //if (arrayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -394,11 +398,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.HyperLink.Count > 0) - { + //if (arrayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -407,7 +411,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (arrayParameterType.Alias.Count > 0) - { + //if (arrayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -453,11 +457,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Category.Count > 0) - { + //if (arrayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -466,13 +470,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); - if (arrayParameterType.Component.Count > 0) - { + //if (arrayParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -481,11 +485,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Definition.Count > 0) - { + //if (arrayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -494,11 +498,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.Dimension.Count > 0) - { + //if (arrayParameterType.Dimension.Count > 0) + //{ writer.WriteStartArray("dimension"u8); foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) @@ -507,11 +511,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedDomain.Count > 0) - { + //if (arrayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -520,11 +524,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.ExcludedPerson.Count > 0) - { + //if (arrayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -533,11 +537,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (arrayParameterType.HyperLink.Count > 0) - { + //if (arrayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -546,7 +550,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -614,6 +618,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -631,6 +640,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -666,6 +680,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListComponent && objectListComponent.Any()) { writer.WriteStartArray("component"u8); @@ -683,6 +702,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -700,6 +724,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDimension && objectListDimension.Any()) { writer.WriteStartArray("dimension"u8); @@ -717,6 +746,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -734,6 +768,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -751,6 +790,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index f949f7920..3c564e71b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - if (binaryNote.Category.Count > 0) - { + //if (binaryNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -90,15 +94,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (binaryNote.ExcludedDomain.Count > 0) - { + //if (binaryNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryNote.ExcludedPerson.Count > 0) - { + //if (binaryNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - if (binaryNote.Category.Count > 0) - { + //if (binaryNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -152,15 +156,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (binaryNote.ExcludedDomain.Count > 0) - { + //if (binaryNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -169,11 +173,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryNote.ExcludedPerson.Count > 0) - { + //if (binaryNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -182,7 +186,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -217,8 +221,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); - if (binaryNote.Category.Count > 0) - { + //if (binaryNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -227,15 +231,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (binaryNote.ExcludedDomain.Count > 0) - { + //if (binaryNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -244,11 +248,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryNote.ExcludedPerson.Count > 0) - { + //if (binaryNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -257,7 +261,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -339,6 +343,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -392,6 +401,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -409,6 +423,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 367d6d45d..c6b17c474 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); - if (binaryRelationshipRule.Alias.Count > 0) - { + //if (binaryRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - if (binaryRelationshipRule.Definition.Count > 0) - { + //if (binaryRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,13 +107,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - if (binaryRelationshipRule.HyperLink.Count > 0) - { + //if (binaryRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); - if (binaryRelationshipRule.Alias.Count > 0) - { + //if (binaryRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -152,13 +156,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - if (binaryRelationshipRule.Definition.Count > 0) - { + //if (binaryRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -167,11 +171,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedDomain.Count > 0) - { + //if (binaryRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -180,11 +184,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedPerson.Count > 0) - { + //if (binaryRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -193,13 +197,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - if (binaryRelationshipRule.HyperLink.Count > 0) - { + //if (binaryRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -208,7 +212,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -234,8 +238,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); - if (binaryRelationshipRule.Alias.Count > 0) - { + //if (binaryRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -244,13 +248,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - if (binaryRelationshipRule.Definition.Count > 0) - { + //if (binaryRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -259,11 +263,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedDomain.Count > 0) - { + //if (binaryRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -272,11 +276,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedPerson.Count > 0) - { + //if (binaryRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -285,13 +289,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - if (binaryRelationshipRule.HyperLink.Count > 0) - { + //if (binaryRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -300,7 +304,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -338,8 +342,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (binaryRelationshipRule.Alias.Count > 0) - { + //if (binaryRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -348,13 +352,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); - if (binaryRelationshipRule.Definition.Count > 0) - { + //if (binaryRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedDomain.Count > 0) - { + //if (binaryRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -376,11 +380,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationshipRule.ExcludedPerson.Count > 0) - { + //if (binaryRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -389,13 +393,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); - if (binaryRelationshipRule.HyperLink.Count > 0) - { + //if (binaryRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -404,7 +408,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -474,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -509,6 +518,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -526,6 +540,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -543,6 +562,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -578,6 +602,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index 72b614708..cff25743b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); - if (binaryRelationship.Category.Count > 0) - { + //if (binaryRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); @@ -106,8 +110,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); - if (binaryRelationship.Category.Count > 0) - { + //if (binaryRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -116,13 +120,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - if (binaryRelationship.ExcludedDomain.Count > 0) - { + //if (binaryRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -131,11 +135,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationship.ExcludedPerson.Count > 0) - { + //if (binaryRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -153,8 +157,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - if (binaryRelationship.ParameterValue.Count > 0) - { + //if (binaryRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -163,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -175,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); - if (binaryRelationship.Category.Count > 0) - { + //if (binaryRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -185,13 +189,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - if (binaryRelationship.ExcludedDomain.Count > 0) - { + //if (binaryRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -200,11 +204,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationship.ExcludedPerson.Count > 0) - { + //if (binaryRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -213,7 +217,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - if (binaryRelationship.ParameterValue.Count > 0) - { + //if (binaryRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -234,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -258,8 +262,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (binaryRelationship.Category.Count > 0) - { + //if (binaryRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -268,13 +272,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); - if (binaryRelationship.ExcludedDomain.Count > 0) - { + //if (binaryRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -283,11 +287,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (binaryRelationship.ExcludedPerson.Count > 0) - { + //if (binaryRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -296,7 +300,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -307,8 +311,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); - if (binaryRelationship.ParameterValue.Count > 0) - { + //if (binaryRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -317,7 +321,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -373,6 +377,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -408,6 +417,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -425,6 +439,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -514,6 +533,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { writer.WriteStartArray("parameterValue"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index 2d94b798b..e03274358 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); - if (book.Category.Count > 0) - { + //if (book.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (book.ExcludedDomain.Count > 0) - { + //if (book.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (book.ExcludedPerson.Count > 0) - { + //if (book.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -131,8 +135,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - if (book.Section.Count > 0) - { + //if (book.Section.Count > 0) + //{ writer.WriteStartArray("section"u8); foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) @@ -141,7 +145,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -149,8 +153,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); - if (book.Category.Count > 0) - { + //if (book.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) @@ -159,15 +163,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (book.ExcludedDomain.Count > 0) - { + //if (book.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (book.ExcludedPerson.Count > 0) - { + //if (book.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -189,7 +193,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -202,8 +206,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - if (book.Section.Count > 0) - { + //if (book.Section.Count > 0) + //{ writer.WriteStartArray("section"u8); foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) @@ -212,7 +216,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -232,8 +236,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (book.Category.Count > 0) - { + //if (book.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) @@ -242,15 +246,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (book.ExcludedDomain.Count > 0) - { + //if (book.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -259,11 +263,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (book.ExcludedPerson.Count > 0) - { + //if (book.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -272,7 +276,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -285,8 +289,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); - if (book.Section.Count > 0) - { + //if (book.Section.Count > 0) + //{ writer.WriteStartArray("section"u8); foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) @@ -295,7 +299,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -347,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -400,6 +409,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -417,6 +431,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -524,6 +543,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSection && objectListSection.Any()) { writer.WriteStartArray("section"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index af83a0c67..db44f2e2e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); - if (booleanParameterType.Alias.Count > 0) - { + //if (booleanParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.Category.Count > 0) - { + //if (booleanParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - if (booleanParameterType.Definition.Count > 0) - { + //if (booleanParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.HyperLink.Count > 0) - { + //if (booleanParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); - if (booleanParameterType.Alias.Count > 0) - { + //if (booleanParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.Category.Count > 0) - { + //if (booleanParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - if (booleanParameterType.Definition.Count > 0) - { + //if (booleanParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedDomain.Count > 0) - { + //if (booleanParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedPerson.Count > 0) - { + //if (booleanParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.HyperLink.Count > 0) - { + //if (booleanParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); - if (booleanParameterType.Alias.Count > 0) - { + //if (booleanParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.Category.Count > 0) - { + //if (booleanParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - if (booleanParameterType.Definition.Count > 0) - { + //if (booleanParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedDomain.Count > 0) - { + //if (booleanParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedPerson.Count > 0) - { + //if (booleanParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.HyperLink.Count > 0) - { + //if (booleanParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (booleanParameterType.Alias.Count > 0) - { + //if (booleanParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.Category.Count > 0) - { + //if (booleanParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); - if (booleanParameterType.Definition.Count > 0) - { + //if (booleanParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedDomain.Count > 0) - { + //if (booleanParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.ExcludedPerson.Count > 0) - { + //if (booleanParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (booleanParameterType.HyperLink.Count > 0) - { + //if (booleanParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -430,7 +434,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -597,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index cf2bb7be9..ef430cb66 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - if (bounds.ExcludedDomain.Count > 0) - { + //if (bounds.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (bounds.ExcludedPerson.Count > 0) - { + //if (bounds.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - if (bounds.ExcludedDomain.Count > 0) - { + //if (bounds.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -137,11 +141,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (bounds.ExcludedPerson.Count > 0) - { + //if (bounds.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -187,8 +191,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); - if (bounds.ExcludedDomain.Count > 0) - { + //if (bounds.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -197,11 +201,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (bounds.ExcludedPerson.Count > 0) - { + //if (bounds.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -210,7 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -294,6 +298,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -311,6 +320,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 8c036b3db..e6ebf2a62 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -101,8 +105,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - if (builtInRuleVerification.Violation.Count > 0) - { + //if (builtInRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -111,7 +115,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -119,8 +123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - if (builtInRuleVerification.ExcludedDomain.Count > 0) - { + //if (builtInRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (builtInRuleVerification.ExcludedPerson.Count > 0) - { + //if (builtInRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,7 +146,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - if (builtInRuleVerification.Violation.Count > 0) - { + //if (builtInRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -178,7 +182,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -186,8 +190,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - if (builtInRuleVerification.ExcludedDomain.Count > 0) - { + //if (builtInRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (builtInRuleVerification.ExcludedPerson.Count > 0) - { + //if (builtInRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -237,8 +241,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - if (builtInRuleVerification.Violation.Count > 0) - { + //if (builtInRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); - if (builtInRuleVerification.ExcludedDomain.Count > 0) - { + //if (builtInRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (builtInRuleVerification.ExcludedPerson.Count > 0) - { + //if (builtInRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -289,7 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -317,8 +321,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - if (builtInRuleVerification.Violation.Count > 0) - { + //if (builtInRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -327,7 +331,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -393,6 +397,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -410,6 +419,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -571,6 +585,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListViolation && objectListViolation.Any()) { writer.WriteStartArray("violation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index a65412b7f..6d20bee16 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); - if (category.Alias.Count > 0) - { + //if (category.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - if (category.Definition.Count > 0) - { + //if (category.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.HyperLink.Count > 0) - { + //if (category.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - if (category.PermissibleClass.Count > 0) - { + //if (category.PermissibleClass.Count > 0) + //{ writer.WriteStartArray("permissibleClass"u8); foreach(var permissibleClassItem in category.PermissibleClass) @@ -137,15 +141,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - if (category.SuperCategory.Count > 0) - { + //if (category.SuperCategory.Count > 0) + //{ writer.WriteStartArray("superCategory"u8); foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) @@ -154,14 +158,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); - if (category.Alias.Count > 0) - { + //if (category.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - if (category.Definition.Count > 0) - { + //if (category.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedDomain.Count > 0) - { + //if (category.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedPerson.Count > 0) - { + //if (category.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.HyperLink.Count > 0) - { + //if (category.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -237,8 +241,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - if (category.PermissibleClass.Count > 0) - { + //if (category.PermissibleClass.Count > 0) + //{ writer.WriteStartArray("permissibleClass"u8); foreach(var permissibleClassItem in category.PermissibleClass) @@ -247,15 +251,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - if (category.SuperCategory.Count > 0) - { + //if (category.SuperCategory.Count > 0) + //{ writer.WriteStartArray("superCategory"u8); foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) @@ -264,14 +268,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); - if (category.Alias.Count > 0) - { + //if (category.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) @@ -280,13 +284,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - if (category.Definition.Count > 0) - { + //if (category.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedDomain.Count > 0) - { + //if (category.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedPerson.Count > 0) - { + //if (category.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -321,11 +325,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.HyperLink.Count > 0) - { + //if (category.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -334,7 +338,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - if (category.PermissibleClass.Count > 0) - { + //if (category.PermissibleClass.Count > 0) + //{ writer.WriteStartArray("permissibleClass"u8); foreach(var permissibleClassItem in category.PermissibleClass) @@ -357,15 +361,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - if (category.SuperCategory.Count > 0) - { + //if (category.SuperCategory.Count > 0) + //{ writer.WriteStartArray("superCategory"u8); foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) @@ -374,7 +378,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); @@ -392,8 +396,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (category.Alias.Count > 0) - { + //if (category.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) @@ -402,13 +406,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); - if (category.Definition.Count > 0) - { + //if (category.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedDomain.Count > 0) - { + //if (category.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -430,11 +434,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.ExcludedPerson.Count > 0) - { + //if (category.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -443,11 +447,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (category.HyperLink.Count > 0) - { + //if (category.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -456,7 +460,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -469,8 +473,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); - if (category.PermissibleClass.Count > 0) - { + //if (category.PermissibleClass.Count > 0) + //{ writer.WriteStartArray("permissibleClass"u8); foreach(var permissibleClassItem in category.PermissibleClass) @@ -479,15 +483,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); - if (category.SuperCategory.Count > 0) - { + //if (category.SuperCategory.Count > 0) + //{ writer.WriteStartArray("superCategory"u8); foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) @@ -496,7 +500,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); @@ -546,6 +550,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -581,6 +590,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -598,6 +612,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -615,6 +634,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -632,6 +656,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -739,6 +768,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPermissibleClass && objectListPermissibleClass.Any()) { writer.WriteStartArray("permissibleClass"u8); @@ -792,6 +826,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSuperCategory && objectListSuperCategory.Any()) { writer.WriteStartArray("superCategory"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index d20de6222..f67ac8059 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); - if (changeProposal.ApprovedBy.Count > 0) - { + //if (changeProposal.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - if (changeProposal.Category.Count > 0) - { + //if (changeProposal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -116,8 +120,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeProposal.Discussion.Count > 0) - { + //if (changeProposal.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -126,11 +130,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedDomain.Count > 0) - { + //if (changeProposal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -139,11 +143,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedPerson.Count > 0) - { + //if (changeProposal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -152,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -173,8 +177,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeProposal.RelatedThing.Count > 0) - { + //if (changeProposal.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -183,15 +187,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - if (changeProposal.SourceAnnotation.Count > 0) - { + //if (changeProposal.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -200,7 +204,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -210,8 +214,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); - if (changeProposal.ApprovedBy.Count > 0) - { + //if (changeProposal.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - if (changeProposal.Category.Count > 0) - { + //if (changeProposal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) @@ -235,7 +239,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -248,8 +252,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeProposal.Discussion.Count > 0) - { + //if (changeProposal.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -258,11 +262,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedDomain.Count > 0) - { + //if (changeProposal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedPerson.Count > 0) - { + //if (changeProposal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -305,8 +309,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeProposal.RelatedThing.Count > 0) - { + //if (changeProposal.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -315,15 +319,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - if (changeProposal.SourceAnnotation.Count > 0) - { + //if (changeProposal.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -332,7 +336,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -354,8 +358,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeProposal.ApprovedBy.Count > 0) - { + //if (changeProposal.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -364,13 +368,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); - if (changeProposal.Category.Count > 0) - { + //if (changeProposal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) @@ -379,7 +383,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -392,8 +396,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeProposal.Discussion.Count > 0) - { + //if (changeProposal.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -402,11 +406,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedDomain.Count > 0) - { + //if (changeProposal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -415,11 +419,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeProposal.ExcludedPerson.Count > 0) - { + //if (changeProposal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -428,7 +432,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -449,8 +453,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeProposal.RelatedThing.Count > 0) - { + //if (changeProposal.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -459,15 +463,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); - if (changeProposal.SourceAnnotation.Count > 0) - { + //if (changeProposal.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -476,7 +480,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -530,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -565,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -672,6 +686,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -689,6 +708,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -706,6 +730,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -813,6 +842,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -866,6 +900,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index 869705705..66b34e2cc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); - if (changeRequest.ApprovedBy.Count > 0) - { + //if (changeRequest.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - if (changeRequest.Category.Count > 0) - { + //if (changeRequest.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeRequest.Discussion.Count > 0) - { + //if (changeRequest.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -124,11 +128,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedDomain.Count > 0) - { + //if (changeRequest.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -137,11 +141,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedPerson.Count > 0) - { + //if (changeRequest.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeRequest.RelatedThing.Count > 0) - { + //if (changeRequest.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -181,15 +185,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - if (changeRequest.SourceAnnotation.Count > 0) - { + //if (changeRequest.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -208,8 +212,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); - if (changeRequest.ApprovedBy.Count > 0) - { + //if (changeRequest.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -218,13 +222,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - if (changeRequest.Category.Count > 0) - { + //if (changeRequest.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) @@ -233,7 +237,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeRequest.Discussion.Count > 0) - { + //if (changeRequest.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedDomain.Count > 0) - { + //if (changeRequest.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -267,11 +271,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedPerson.Count > 0) - { + //if (changeRequest.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -280,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -301,8 +305,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeRequest.RelatedThing.Count > 0) - { + //if (changeRequest.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -311,15 +315,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - if (changeRequest.SourceAnnotation.Count > 0) - { + //if (changeRequest.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -328,7 +332,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -350,8 +354,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeRequest.ApprovedBy.Count > 0) - { + //if (changeRequest.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -360,13 +364,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); - if (changeRequest.Category.Count > 0) - { + //if (changeRequest.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) @@ -375,7 +379,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (changeRequest.Discussion.Count > 0) - { + //if (changeRequest.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -396,11 +400,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedDomain.Count > 0) - { + //if (changeRequest.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (changeRequest.ExcludedPerson.Count > 0) - { + //if (changeRequest.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -422,7 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (changeRequest.RelatedThing.Count > 0) - { + //if (changeRequest.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -453,15 +457,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); - if (changeRequest.SourceAnnotation.Count > 0) - { + //if (changeRequest.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -470,7 +474,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -524,6 +528,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -559,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -648,6 +662,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -665,6 +684,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -682,6 +706,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -789,6 +818,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -842,6 +876,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index fd1787c24..10e2c3279 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -99,8 +103,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - if (citation.ExcludedDomain.Count > 0) - { + //if (citation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (citation.ExcludedPerson.Count > 0) - { + //if (citation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -146,8 +150,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - if (citation.ExcludedDomain.Count > 0) - { + //if (citation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -156,11 +160,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (citation.ExcludedPerson.Count > 0) - { + //if (citation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -169,7 +173,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -206,8 +210,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); - if (citation.ExcludedDomain.Count > 0) - { + //if (citation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -216,11 +220,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (citation.ExcludedPerson.Count > 0) - { + //if (citation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -229,7 +233,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -313,6 +317,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -330,6 +339,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index aaf18cec2..21226aba2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -99,8 +103,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - if (color.ExcludedDomain.Count > 0) - { + //if (color.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (color.ExcludedPerson.Count > 0) - { + //if (color.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -144,8 +148,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - if (color.ExcludedDomain.Count > 0) - { + //if (color.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -154,11 +158,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (color.ExcludedPerson.Count > 0) - { + //if (color.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -167,7 +171,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -202,8 +206,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); - if (color.ExcludedDomain.Count > 0) - { + //if (color.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -212,11 +216,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (color.ExcludedPerson.Count > 0) - { + //if (color.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -225,7 +229,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -323,6 +327,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -340,6 +349,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 24f804f2f..75386f456 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -82,8 +86,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (commonFileStore.File.Count > 0) - { + //if (commonFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -92,11 +96,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.Folder.Count > 0) - { + //if (commonFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -105,7 +109,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -123,8 +127,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (commonFileStore.ExcludedDomain.Count > 0) - { + //if (commonFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -133,11 +137,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.ExcludedPerson.Count > 0) - { + //if (commonFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -146,11 +150,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.File.Count > 0) - { + //if (commonFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -159,11 +163,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.Folder.Count > 0) - { + //if (commonFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -172,7 +176,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -192,8 +196,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (commonFileStore.ExcludedDomain.Count > 0) - { + //if (commonFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -202,11 +206,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.ExcludedPerson.Count > 0) - { + //if (commonFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -215,11 +219,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.File.Count > 0) - { + //if (commonFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -228,11 +232,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.Folder.Count > 0) - { + //if (commonFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -241,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -274,8 +278,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (commonFileStore.ExcludedDomain.Count > 0) - { + //if (commonFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -284,11 +288,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.ExcludedPerson.Count > 0) - { + //if (commonFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -297,11 +301,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.File.Count > 0) - { + //if (commonFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -310,11 +314,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (commonFileStore.Folder.Count > 0) - { + //if (commonFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -323,7 +327,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -419,6 +423,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -436,6 +445,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -453,6 +467,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFile && objectListFile.Any()) { writer.WriteStartArray("file"u8); @@ -470,6 +489,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFolder && objectListFolder.Any()) { writer.WriteStartArray("folder"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index c38e5d92f..acff7df8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); - if (compoundParameterType.Alias.Count > 0) - { + //if (compoundParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Category.Count > 0) - { + //if (compoundParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - if (compoundParameterType.Component.Count > 0) - { + //if (compoundParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Definition.Count > 0) - { + //if (compoundParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.HyperLink.Count > 0) - { + //if (compoundParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -142,7 +146,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -162,8 +166,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); - if (compoundParameterType.Alias.Count > 0) - { + //if (compoundParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -172,11 +176,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Category.Count > 0) - { + //if (compoundParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -185,13 +189,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - if (compoundParameterType.Component.Count > 0) - { + //if (compoundParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -200,11 +204,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Definition.Count > 0) - { + //if (compoundParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -213,11 +217,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedDomain.Count > 0) - { + //if (compoundParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -226,11 +230,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedPerson.Count > 0) - { + //if (compoundParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -239,11 +243,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.HyperLink.Count > 0) - { + //if (compoundParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -252,7 +256,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -274,8 +278,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); - if (compoundParameterType.Alias.Count > 0) - { + //if (compoundParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -284,11 +288,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Category.Count > 0) - { + //if (compoundParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -297,13 +301,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - if (compoundParameterType.Component.Count > 0) - { + //if (compoundParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -312,11 +316,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Definition.Count > 0) - { + //if (compoundParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -325,11 +329,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedDomain.Count > 0) - { + //if (compoundParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -338,11 +342,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedPerson.Count > 0) - { + //if (compoundParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -351,11 +355,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.HyperLink.Count > 0) - { + //if (compoundParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -364,7 +368,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -398,8 +402,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (compoundParameterType.Alias.Count > 0) - { + //if (compoundParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -408,11 +412,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Category.Count > 0) - { + //if (compoundParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -421,13 +425,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); - if (compoundParameterType.Component.Count > 0) - { + //if (compoundParameterType.Component.Count > 0) + //{ writer.WriteStartArray("component"u8); foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) @@ -436,11 +440,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.Definition.Count > 0) - { + //if (compoundParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -449,11 +453,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedDomain.Count > 0) - { + //if (compoundParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -462,11 +466,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.ExcludedPerson.Count > 0) - { + //if (compoundParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -475,11 +479,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (compoundParameterType.HyperLink.Count > 0) - { + //if (compoundParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -488,7 +492,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -554,6 +558,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -571,6 +580,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -606,6 +620,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListComponent && objectListComponent.Any()) { writer.WriteStartArray("component"u8); @@ -623,6 +642,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -640,6 +664,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -657,6 +686,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -674,6 +708,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index 853f76c39..e19efbb0a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); - if (constant.Alias.Count > 0) - { + //if (constant.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.Category.Count > 0) - { + //if (constant.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - if (constant.Definition.Count > 0) - { + //if (constant.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.HyperLink.Count > 0) - { + //if (constant.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -159,8 +163,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); - if (constant.Alias.Count > 0) - { + //if (constant.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) @@ -169,11 +173,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.Category.Count > 0) - { + //if (constant.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) @@ -182,13 +186,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - if (constant.Definition.Count > 0) - { + //if (constant.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) @@ -197,11 +201,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedDomain.Count > 0) - { + //if (constant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -210,11 +214,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedPerson.Count > 0) - { + //if (constant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -223,11 +227,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.HyperLink.Count > 0) - { + //if (constant.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -236,7 +240,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -268,8 +272,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); - if (constant.Alias.Count > 0) - { + //if (constant.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.Category.Count > 0) - { + //if (constant.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) @@ -291,13 +295,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - if (constant.Definition.Count > 0) - { + //if (constant.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) @@ -306,11 +310,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedDomain.Count > 0) - { + //if (constant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -319,11 +323,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedPerson.Count > 0) - { + //if (constant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -332,11 +336,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.HyperLink.Count > 0) - { + //if (constant.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -345,7 +349,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -389,8 +393,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (constant.Alias.Count > 0) - { + //if (constant.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) @@ -399,11 +403,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.Category.Count > 0) - { + //if (constant.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) @@ -412,13 +416,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); - if (constant.Definition.Count > 0) - { + //if (constant.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) @@ -427,11 +431,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedDomain.Count > 0) - { + //if (constant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -440,11 +444,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.ExcludedPerson.Count > 0) - { + //if (constant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -453,11 +457,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (constant.HyperLink.Count > 0) - { + //if (constant.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -466,7 +470,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -542,6 +546,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -559,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -594,6 +608,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -611,6 +630,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -628,6 +652,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -645,6 +674,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 6b9fea444..9db6fcb14 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); - if (contractChangeNotice.ApprovedBy.Count > 0) - { + //if (contractChangeNotice.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - if (contractChangeNotice.Category.Count > 0) - { + //if (contractChangeNotice.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -116,8 +120,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (contractChangeNotice.Discussion.Count > 0) - { + //if (contractChangeNotice.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -126,11 +130,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedDomain.Count > 0) - { + //if (contractChangeNotice.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -139,11 +143,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedPerson.Count > 0) - { + //if (contractChangeNotice.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -152,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -173,8 +177,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (contractChangeNotice.RelatedThing.Count > 0) - { + //if (contractChangeNotice.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -183,15 +187,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - if (contractChangeNotice.SourceAnnotation.Count > 0) - { + //if (contractChangeNotice.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -200,7 +204,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -210,8 +214,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); - if (contractChangeNotice.ApprovedBy.Count > 0) - { + //if (contractChangeNotice.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - if (contractChangeNotice.Category.Count > 0) - { + //if (contractChangeNotice.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) @@ -235,7 +239,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -248,8 +252,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (contractChangeNotice.Discussion.Count > 0) - { + //if (contractChangeNotice.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -258,11 +262,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedDomain.Count > 0) - { + //if (contractChangeNotice.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedPerson.Count > 0) - { + //if (contractChangeNotice.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -305,8 +309,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (contractChangeNotice.RelatedThing.Count > 0) - { + //if (contractChangeNotice.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -315,15 +319,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - if (contractChangeNotice.SourceAnnotation.Count > 0) - { + //if (contractChangeNotice.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -332,7 +336,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -354,8 +358,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (contractChangeNotice.ApprovedBy.Count > 0) - { + //if (contractChangeNotice.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -364,13 +368,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); - if (contractChangeNotice.Category.Count > 0) - { + //if (contractChangeNotice.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) @@ -379,7 +383,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -392,8 +396,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (contractChangeNotice.Discussion.Count > 0) - { + //if (contractChangeNotice.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -402,11 +406,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedDomain.Count > 0) - { + //if (contractChangeNotice.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -415,11 +419,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (contractChangeNotice.ExcludedPerson.Count > 0) - { + //if (contractChangeNotice.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -428,7 +432,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -449,8 +453,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (contractChangeNotice.RelatedThing.Count > 0) - { + //if (contractChangeNotice.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -459,15 +463,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); - if (contractChangeNotice.SourceAnnotation.Count > 0) - { + //if (contractChangeNotice.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -476,7 +480,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -530,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -565,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -672,6 +686,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -689,6 +708,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -706,6 +730,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -813,6 +842,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -866,6 +900,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index 453204d86..eee1f859c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); - if (cyclicRatioScale.Alias.Count > 0) - { + //if (cyclicRatioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - if (cyclicRatioScale.Definition.Count > 0) - { + //if (cyclicRatioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.HyperLink.Count > 0) - { + //if (cyclicRatioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - { + //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -160,8 +164,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - if (cyclicRatioScale.ValueDefinition.Count > 0) - { + //if (cyclicRatioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -170,14 +174,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); - if (cyclicRatioScale.Alias.Count > 0) - { + //if (cyclicRatioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -186,13 +190,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - if (cyclicRatioScale.Definition.Count > 0) - { + //if (cyclicRatioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -201,11 +205,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedDomain.Count > 0) - { + //if (cyclicRatioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -214,11 +218,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedPerson.Count > 0) - { + //if (cyclicRatioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -227,11 +231,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.HyperLink.Count > 0) - { + //if (cyclicRatioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -240,7 +244,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -251,8 +255,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - { + //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -286,8 +290,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - if (cyclicRatioScale.ValueDefinition.Count > 0) - { + //if (cyclicRatioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -296,14 +300,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); - if (cyclicRatioScale.Alias.Count > 0) - { + //if (cyclicRatioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -312,13 +316,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - if (cyclicRatioScale.Definition.Count > 0) - { + //if (cyclicRatioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedDomain.Count > 0) - { + //if (cyclicRatioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedPerson.Count > 0) - { + //if (cyclicRatioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.HyperLink.Count > 0) - { + //if (cyclicRatioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -366,7 +370,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -377,8 +381,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - { + //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -387,7 +391,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -414,8 +418,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - if (cyclicRatioScale.ValueDefinition.Count > 0) - { + //if (cyclicRatioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -424,7 +428,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -440,8 +444,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (cyclicRatioScale.Alias.Count > 0) - { + //if (cyclicRatioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -450,13 +454,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); - if (cyclicRatioScale.Definition.Count > 0) - { + //if (cyclicRatioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -465,11 +469,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedDomain.Count > 0) - { + //if (cyclicRatioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -478,11 +482,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.ExcludedPerson.Count > 0) - { + //if (cyclicRatioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -491,11 +495,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (cyclicRatioScale.HyperLink.Count > 0) - { + //if (cyclicRatioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -504,7 +508,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -515,8 +519,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); - if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - { + //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -525,7 +529,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -552,8 +556,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); - if (cyclicRatioScale.ValueDefinition.Count > 0) - { + //if (cyclicRatioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -562,7 +566,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -610,6 +614,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -645,6 +654,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -662,6 +676,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -679,6 +698,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -696,6 +720,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -785,6 +814,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { writer.WriteStartArray("mappingToReferenceScale"u8); @@ -1018,6 +1052,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 6d9a7f002..1da9a8d68 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); - if (dateParameterType.Alias.Count > 0) - { + //if (dateParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.Category.Count > 0) - { + //if (dateParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - if (dateParameterType.Definition.Count > 0) - { + //if (dateParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.HyperLink.Count > 0) - { + //if (dateParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); - if (dateParameterType.Alias.Count > 0) - { + //if (dateParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.Category.Count > 0) - { + //if (dateParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - if (dateParameterType.Definition.Count > 0) - { + //if (dateParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedDomain.Count > 0) - { + //if (dateParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedPerson.Count > 0) - { + //if (dateParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.HyperLink.Count > 0) - { + //if (dateParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); - if (dateParameterType.Alias.Count > 0) - { + //if (dateParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.Category.Count > 0) - { + //if (dateParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - if (dateParameterType.Definition.Count > 0) - { + //if (dateParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedDomain.Count > 0) - { + //if (dateParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedPerson.Count > 0) - { + //if (dateParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.HyperLink.Count > 0) - { + //if (dateParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (dateParameterType.Alias.Count > 0) - { + //if (dateParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.Category.Count > 0) - { + //if (dateParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); - if (dateParameterType.Definition.Count > 0) - { + //if (dateParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedDomain.Count > 0) - { + //if (dateParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.ExcludedPerson.Count > 0) - { + //if (dateParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateParameterType.HyperLink.Count > 0) - { + //if (dateParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -430,7 +434,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -597,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index c8662ba45..5bfab0a5f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); - if (dateTimeParameterType.Alias.Count > 0) - { + //if (dateTimeParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.Category.Count > 0) - { + //if (dateTimeParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - if (dateTimeParameterType.Definition.Count > 0) - { + //if (dateTimeParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.HyperLink.Count > 0) - { + //if (dateTimeParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); - if (dateTimeParameterType.Alias.Count > 0) - { + //if (dateTimeParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.Category.Count > 0) - { + //if (dateTimeParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - if (dateTimeParameterType.Definition.Count > 0) - { + //if (dateTimeParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedDomain.Count > 0) - { + //if (dateTimeParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedPerson.Count > 0) - { + //if (dateTimeParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.HyperLink.Count > 0) - { + //if (dateTimeParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); - if (dateTimeParameterType.Alias.Count > 0) - { + //if (dateTimeParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.Category.Count > 0) - { + //if (dateTimeParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - if (dateTimeParameterType.Definition.Count > 0) - { + //if (dateTimeParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedDomain.Count > 0) - { + //if (dateTimeParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedPerson.Count > 0) - { + //if (dateTimeParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.HyperLink.Count > 0) - { + //if (dateTimeParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (dateTimeParameterType.Alias.Count > 0) - { + //if (dateTimeParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.Category.Count > 0) - { + //if (dateTimeParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); - if (dateTimeParameterType.Definition.Count > 0) - { + //if (dateTimeParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedDomain.Count > 0) - { + //if (dateTimeParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.ExcludedPerson.Count > 0) - { + //if (dateTimeParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dateTimeParameterType.HyperLink.Count > 0) - { + //if (dateTimeParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -430,7 +434,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -597,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index aec54665d..4d1c07d78 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); - if (decompositionRule.Alias.Count > 0) - { + //if (decompositionRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - if (decompositionRule.ContainedCategory.Count > 0) - { + //if (decompositionRule.ContainedCategory.Count > 0) + //{ writer.WriteStartArray("containedCategory"u8); foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) @@ -103,13 +107,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - if (decompositionRule.Definition.Count > 0) - { + //if (decompositionRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.HyperLink.Count > 0) - { + //if (decompositionRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -160,8 +164,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); - if (decompositionRule.Alias.Count > 0) - { + //if (decompositionRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - if (decompositionRule.ContainedCategory.Count > 0) - { + //if (decompositionRule.ContainedCategory.Count > 0) + //{ writer.WriteStartArray("containedCategory"u8); foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) @@ -185,13 +189,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - if (decompositionRule.Definition.Count > 0) - { + //if (decompositionRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -200,11 +204,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedDomain.Count > 0) - { + //if (decompositionRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -213,11 +217,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedPerson.Count > 0) - { + //if (decompositionRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -226,11 +230,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.HyperLink.Count > 0) - { + //if (decompositionRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -239,7 +243,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -270,8 +274,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); - if (decompositionRule.Alias.Count > 0) - { + //if (decompositionRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -280,13 +284,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - if (decompositionRule.ContainedCategory.Count > 0) - { + //if (decompositionRule.ContainedCategory.Count > 0) + //{ writer.WriteStartArray("containedCategory"u8); foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) @@ -295,13 +299,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - if (decompositionRule.Definition.Count > 0) - { + //if (decompositionRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -310,11 +314,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedDomain.Count > 0) - { + //if (decompositionRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -323,11 +327,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedPerson.Count > 0) - { + //if (decompositionRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -336,11 +340,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.HyperLink.Count > 0) - { + //if (decompositionRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -349,7 +353,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -392,8 +396,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (decompositionRule.Alias.Count > 0) - { + //if (decompositionRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -402,13 +406,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); - if (decompositionRule.ContainedCategory.Count > 0) - { + //if (decompositionRule.ContainedCategory.Count > 0) + //{ writer.WriteStartArray("containedCategory"u8); foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) @@ -417,13 +421,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); - if (decompositionRule.Definition.Count > 0) - { + //if (decompositionRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -432,11 +436,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedDomain.Count > 0) - { + //if (decompositionRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -445,11 +449,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.ExcludedPerson.Count > 0) - { + //if (decompositionRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -458,11 +462,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (decompositionRule.HyperLink.Count > 0) - { + //if (decompositionRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -471,7 +475,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -546,6 +550,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -581,6 +590,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListContainedCategory && objectListContainedCategory.Any()) { writer.WriteStartArray("containedCategory"u8); @@ -616,6 +630,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -633,6 +652,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -650,6 +674,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -667,6 +696,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 061f77804..6852ba246 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); - if (definition.Citation.Count > 0) - { + //if (definition.Citation.Count > 0) + //{ writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - if (definition.Example.Count > 0) - { + //if (definition.Example.Count > 0) + //{ writer.WriteStartArray("example"u8); foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) @@ -105,15 +109,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); writer.WriteStringValue(definition.LanguageCode); - if (definition.Note.Count > 0) - { + //if (definition.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -130,8 +134,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); - if (definition.Citation.Count > 0) - { + //if (definition.Citation.Count > 0) + //{ writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -140,15 +144,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - if (definition.Example.Count > 0) - { + //if (definition.Example.Count > 0) + //{ writer.WriteStartArray("example"u8); foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedDomain.Count > 0) - { + //if (definition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedPerson.Count > 0) - { + //if (definition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,7 +187,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -192,8 +196,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (definition.Note.Count > 0) - { + //if (definition.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -210,8 +214,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); - if (definition.Citation.Count > 0) - { + //if (definition.Citation.Count > 0) + //{ writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -220,15 +224,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - if (definition.Example.Count > 0) - { + //if (definition.Example.Count > 0) + //{ writer.WriteStartArray("example"u8); foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) @@ -237,11 +241,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedDomain.Count > 0) - { + //if (definition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -250,11 +254,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedPerson.Count > 0) - { + //if (definition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -263,7 +267,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -272,8 +276,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (definition.Note.Count > 0) - { + //if (definition.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -282,7 +286,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -302,8 +306,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (definition.Citation.Count > 0) - { + //if (definition.Citation.Count > 0) + //{ writer.WriteStartArray("citation"u8); foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) @@ -312,15 +316,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); - if (definition.Example.Count > 0) - { + //if (definition.Example.Count > 0) + //{ writer.WriteStartArray("example"u8); foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) @@ -329,11 +333,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedDomain.Count > 0) - { + //if (definition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -342,11 +346,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (definition.ExcludedPerson.Count > 0) - { + //if (definition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -355,7 +359,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -364,8 +368,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (definition.Note.Count > 0) - { + //if (definition.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -374,7 +378,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -426,6 +430,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCitation && objectListCitation.Any()) { writer.WriteStartArray("citation"u8); @@ -479,6 +488,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExample && objectListExample.Any()) { writer.WriteStartArray("example"u8); @@ -496,6 +510,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -513,6 +532,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -584,6 +608,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListNote && objectListNote.Any()) { writer.WriteStartArray("note"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index cb1753bc2..1812e52d1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) - { + //if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) - { + //if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); @@ -143,8 +147,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); - if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) - { + //if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -153,11 +157,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) - { + //if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -166,7 +170,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); @@ -253,6 +257,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -270,6 +279,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index d2e722d3c..cb1f96017 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); - if (derivedQuantityKind.Alias.Count > 0) - { + //if (derivedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.Category.Count > 0) - { + //if (derivedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,15 +105,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - if (derivedQuantityKind.Definition.Count > 0) - { + //if (derivedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.HyperLink.Count > 0) - { + //if (derivedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - if (derivedQuantityKind.PossibleScale.Count > 0) - { + //if (derivedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -150,13 +154,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - if (derivedQuantityKind.QuantityKindFactor.Count > 0) - { + //if (derivedQuantityKind.QuantityKindFactor.Count > 0) + //{ writer.WriteStartArray("quantityKindFactor"u8); foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -165,7 +169,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -177,8 +181,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); - if (derivedQuantityKind.Alias.Count > 0) - { + //if (derivedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -187,11 +191,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.Category.Count > 0) - { + //if (derivedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -200,15 +204,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - if (derivedQuantityKind.Definition.Count > 0) - { + //if (derivedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedDomain.Count > 0) - { + //if (derivedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -230,11 +234,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedPerson.Count > 0) - { + //if (derivedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -243,11 +247,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.HyperLink.Count > 0) - { + //if (derivedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -256,7 +260,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -267,8 +271,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - if (derivedQuantityKind.PossibleScale.Count > 0) - { + //if (derivedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -277,13 +281,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - if (derivedQuantityKind.QuantityKindFactor.Count > 0) - { + //if (derivedQuantityKind.QuantityKindFactor.Count > 0) + //{ writer.WriteStartArray("quantityKindFactor"u8); foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -292,7 +296,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -304,8 +308,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); - if (derivedQuantityKind.Alias.Count > 0) - { + //if (derivedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.Category.Count > 0) - { + //if (derivedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -327,15 +331,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - if (derivedQuantityKind.Definition.Count > 0) - { + //if (derivedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -344,11 +348,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedDomain.Count > 0) - { + //if (derivedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -357,11 +361,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedPerson.Count > 0) - { + //if (derivedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -370,11 +374,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.HyperLink.Count > 0) - { + //if (derivedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -383,7 +387,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -394,8 +398,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - if (derivedQuantityKind.PossibleScale.Count > 0) - { + //if (derivedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -404,13 +408,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - if (derivedQuantityKind.QuantityKindFactor.Count > 0) - { + //if (derivedQuantityKind.QuantityKindFactor.Count > 0) + //{ writer.WriteStartArray("quantityKindFactor"u8); foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -419,7 +423,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (derivedQuantityKind.Alias.Count > 0) - { + //if (derivedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -453,11 +457,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.Category.Count > 0) - { + //if (derivedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -466,15 +470,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); - if (derivedQuantityKind.Definition.Count > 0) - { + //if (derivedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -483,11 +487,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedDomain.Count > 0) - { + //if (derivedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -496,11 +500,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.ExcludedPerson.Count > 0) - { + //if (derivedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -509,11 +513,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedQuantityKind.HyperLink.Count > 0) - { + //if (derivedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -522,7 +526,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -533,8 +537,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); - if (derivedQuantityKind.PossibleScale.Count > 0) - { + //if (derivedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -543,13 +547,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); - if (derivedQuantityKind.QuantityKindFactor.Count > 0) - { + //if (derivedQuantityKind.QuantityKindFactor.Count > 0) + //{ writer.WriteStartArray("quantityKindFactor"u8); foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -558,7 +562,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -614,6 +618,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -631,6 +640,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -684,6 +698,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -701,6 +720,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -718,6 +742,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -735,6 +764,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -824,6 +858,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { writer.WriteStartArray("possibleScale"u8); @@ -859,6 +898,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListQuantityKindFactor && objectListQuantityKindFactor.Any()) { writer.WriteStartArray("quantityKindFactor"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index 35f715ff3..9ece18663 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); - if (derivedUnit.Alias.Count > 0) - { + //if (derivedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - if (derivedUnit.Definition.Count > 0) - { + //if (derivedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.HyperLink.Count > 0) - { + //if (derivedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); - if (derivedUnit.UnitFactor.Count > 0) - { + //if (derivedUnit.UnitFactor.Count > 0) + //{ writer.WriteStartArray("unitFactor"u8); foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -139,14 +143,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); - if (derivedUnit.Alias.Count > 0) - { + //if (derivedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - if (derivedUnit.Definition.Count > 0) - { + //if (derivedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedDomain.Count > 0) - { + //if (derivedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedPerson.Count > 0) - { + //if (derivedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.HyperLink.Count > 0) - { + //if (derivedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); - if (derivedUnit.UnitFactor.Count > 0) - { + //if (derivedUnit.UnitFactor.Count > 0) + //{ writer.WriteStartArray("unitFactor"u8); foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -234,14 +238,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); - if (derivedUnit.Alias.Count > 0) - { + //if (derivedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,13 +254,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - if (derivedUnit.Definition.Count > 0) - { + //if (derivedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedDomain.Count > 0) - { + //if (derivedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedPerson.Count > 0) - { + //if (derivedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.HyperLink.Count > 0) - { + //if (derivedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -304,7 +308,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -321,8 +325,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); - if (derivedUnit.UnitFactor.Count > 0) - { + //if (derivedUnit.UnitFactor.Count > 0) + //{ writer.WriteStartArray("unitFactor"u8); foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -331,7 +335,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (derivedUnit.Alias.Count > 0) - { + //if (derivedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,13 +361,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); - if (derivedUnit.Definition.Count > 0) - { + //if (derivedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -372,11 +376,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedDomain.Count > 0) - { + //if (derivedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.ExcludedPerson.Count > 0) - { + //if (derivedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (derivedUnit.HyperLink.Count > 0) - { + //if (derivedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -411,7 +415,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -428,8 +432,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); - if (derivedUnit.UnitFactor.Count > 0) - { + //if (derivedUnit.UnitFactor.Count > 0) + //{ writer.WriteStartArray("unitFactor"u8); foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) @@ -438,7 +442,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -521,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -715,6 +744,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUnitFactor && objectListUnitFactor.Any()) { writer.WriteStartArray("unitFactor"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index 00d1faf15..a04c896c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); - if (diagramCanvas.Bounds.Count > 0) - { + //if (diagramCanvas.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (diagramCanvas.DiagramElement.Count > 0) - { + //if (diagramCanvas.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedDomain.Count > 0) - { + //if (diagramCanvas.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedPerson.Count > 0) - { + //if (diagramCanvas.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); - if (diagramCanvas.Bounds.Count > 0) - { + //if (diagramCanvas.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -155,15 +159,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (diagramCanvas.DiagramElement.Count > 0) - { + //if (diagramCanvas.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -172,11 +176,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedDomain.Count > 0) - { + //if (diagramCanvas.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedPerson.Count > 0) - { + //if (diagramCanvas.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramCanvas.Bounds.Count > 0) - { + //if (diagramCanvas.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -234,15 +238,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (diagramCanvas.DiagramElement.Count > 0) - { + //if (diagramCanvas.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -251,11 +255,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedDomain.Count > 0) - { + //if (diagramCanvas.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -264,11 +268,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramCanvas.ExcludedPerson.Count > 0) - { + //if (diagramCanvas.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -277,7 +281,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -335,6 +339,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { writer.WriteStartArray("bounds"u8); @@ -388,6 +397,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { writer.WriteStartArray("diagramElement"u8); @@ -405,6 +419,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -422,6 +441,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 44ee73ce4..72bd96c1c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); - if (diagramEdge.Bounds.Count > 0) - { + //if (diagramEdge.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -103,8 +107,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramEdge.DiagramElement.Count > 0) - { + //if (diagramEdge.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -113,11 +117,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedDomain.Count > 0) - { + //if (diagramEdge.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -126,11 +130,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedPerson.Count > 0) - { + //if (diagramEdge.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -139,13 +143,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - if (diagramEdge.LocalStyle.Count > 0) - { + //if (diagramEdge.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -154,15 +158,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - if (diagramEdge.Point.Count > 0) - { + //if (diagramEdge.Point.Count > 0) + //{ writer.WriteStartArray("point"u8); foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) @@ -171,7 +175,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -194,8 +198,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); - if (diagramEdge.Bounds.Count > 0) - { + //if (diagramEdge.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -204,7 +208,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -219,8 +223,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramEdge.DiagramElement.Count > 0) - { + //if (diagramEdge.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -229,11 +233,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedDomain.Count > 0) - { + //if (diagramEdge.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -242,11 +246,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedPerson.Count > 0) - { + //if (diagramEdge.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -255,13 +259,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - if (diagramEdge.LocalStyle.Count > 0) - { + //if (diagramEdge.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -270,15 +274,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - if (diagramEdge.Point.Count > 0) - { + //if (diagramEdge.Point.Count > 0) + //{ writer.WriteStartArray("point"u8); foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) @@ -287,7 +291,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -322,8 +326,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramEdge.Bounds.Count > 0) - { + //if (diagramEdge.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -332,7 +336,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramEdge.DiagramElement.Count > 0) - { + //if (diagramEdge.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -357,11 +361,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedDomain.Count > 0) - { + //if (diagramEdge.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -370,11 +374,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramEdge.ExcludedPerson.Count > 0) - { + //if (diagramEdge.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -383,13 +387,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); - if (diagramEdge.LocalStyle.Count > 0) - { + //if (diagramEdge.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -398,15 +402,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); - if (diagramEdge.Point.Count > 0) - { + //if (diagramEdge.Point.Count > 0) + //{ writer.WriteStartArray("point"u8); foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) @@ -415,7 +419,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); @@ -482,6 +486,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { writer.WriteStartArray("bounds"u8); @@ -535,6 +544,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { writer.WriteStartArray("diagramElement"u8); @@ -552,6 +566,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -569,6 +588,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -604,6 +628,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) { writer.WriteStartArray("localStyle"u8); @@ -657,6 +686,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPoint && objectListPoint.Any()) { writer.WriteStartArray("point"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 414c594bd..45514f249 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); - if (diagramObject.Bounds.Count > 0) - { + //if (diagramObject.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -103,8 +107,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramObject.DiagramElement.Count > 0) - { + //if (diagramObject.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -113,13 +117,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - if (diagramObject.ExcludedDomain.Count > 0) - { + //if (diagramObject.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -128,11 +132,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramObject.ExcludedPerson.Count > 0) - { + //if (diagramObject.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -141,13 +145,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - if (diagramObject.LocalStyle.Count > 0) - { + //if (diagramObject.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -156,7 +160,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -181,8 +185,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); - if (diagramObject.Bounds.Count > 0) - { + //if (diagramObject.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -191,7 +195,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -206,8 +210,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramObject.DiagramElement.Count > 0) - { + //if (diagramObject.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -216,13 +220,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - if (diagramObject.ExcludedDomain.Count > 0) - { + //if (diagramObject.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramObject.ExcludedPerson.Count > 0) - { + //if (diagramObject.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,13 +248,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - if (diagramObject.LocalStyle.Count > 0) - { + //if (diagramObject.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -259,7 +263,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -296,8 +300,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramObject.Bounds.Count > 0) - { + //if (diagramObject.Bounds.Count > 0) + //{ writer.WriteStartArray("bounds"u8); foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) @@ -306,7 +310,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); @@ -321,8 +325,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (diagramObject.DiagramElement.Count > 0) - { + //if (diagramObject.DiagramElement.Count > 0) + //{ writer.WriteStartArray("diagramElement"u8); foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) @@ -331,13 +335,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); - if (diagramObject.ExcludedDomain.Count > 0) - { + //if (diagramObject.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -346,11 +350,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (diagramObject.ExcludedPerson.Count > 0) - { + //if (diagramObject.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -359,13 +363,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); - if (diagramObject.LocalStyle.Count > 0) - { + //if (diagramObject.LocalStyle.Count > 0) + //{ writer.WriteStartArray("localStyle"u8); foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) @@ -374,7 +378,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -443,6 +447,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBounds && objectListBounds.Any()) { writer.WriteStartArray("bounds"u8); @@ -496,6 +505,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) { writer.WriteStartArray("diagramElement"u8); @@ -531,6 +545,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -548,6 +567,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -583,6 +607,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) { writer.WriteStartArray("localStyle"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index ef33f54c1..66cda0f2d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -82,8 +86,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (domainFileStore.File.Count > 0) - { + //if (domainFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -92,11 +96,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.Folder.Count > 0) - { + //if (domainFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -105,7 +109,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -125,8 +129,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (domainFileStore.ExcludedDomain.Count > 0) - { + //if (domainFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -135,11 +139,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.ExcludedPerson.Count > 0) - { + //if (domainFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -148,11 +152,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.File.Count > 0) - { + //if (domainFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -161,11 +165,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.Folder.Count > 0) - { + //if (domainFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -174,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -196,8 +200,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (domainFileStore.ExcludedDomain.Count > 0) - { + //if (domainFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.ExcludedPerson.Count > 0) - { + //if (domainFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -219,11 +223,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.File.Count > 0) - { + //if (domainFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -232,11 +236,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.Folder.Count > 0) - { + //if (domainFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -245,7 +249,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -280,8 +284,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (domainFileStore.ExcludedDomain.Count > 0) - { + //if (domainFileStore.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -290,11 +294,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.ExcludedPerson.Count > 0) - { + //if (domainFileStore.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -303,11 +307,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.File.Count > 0) - { + //if (domainFileStore.File.Count > 0) + //{ writer.WriteStartArray("file"u8); foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) @@ -316,11 +320,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainFileStore.Folder.Count > 0) - { + //if (domainFileStore.Folder.Count > 0) + //{ writer.WriteStartArray("folder"u8); foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) @@ -329,7 +333,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -427,6 +431,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -444,6 +453,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -461,6 +475,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFile && objectListFile.Any()) { writer.WriteStartArray("file"u8); @@ -478,6 +497,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFolder && objectListFolder.Any()) { writer.WriteStartArray("folder"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index dadb841c3..2f40b4152 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); - if (domainOfExpertiseGroup.Alias.Count > 0) - { + //if (domainOfExpertiseGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - if (domainOfExpertiseGroup.Definition.Count > 0) - { + //if (domainOfExpertiseGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.Domain.Count > 0) - { + //if (domainOfExpertiseGroup.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.HyperLink.Count > 0) - { + //if (domainOfExpertiseGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); - if (domainOfExpertiseGroup.Alias.Count > 0) - { + //if (domainOfExpertiseGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - if (domainOfExpertiseGroup.Definition.Count > 0) - { + //if (domainOfExpertiseGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.Domain.Count > 0) - { + //if (domainOfExpertiseGroup.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.HyperLink.Count > 0) - { + //if (domainOfExpertiseGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); - if (domainOfExpertiseGroup.Alias.Count > 0) - { + //if (domainOfExpertiseGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,13 +254,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - if (domainOfExpertiseGroup.Definition.Count > 0) - { + //if (domainOfExpertiseGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.Domain.Count > 0) - { + //if (domainOfExpertiseGroup.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -304,11 +308,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.HyperLink.Count > 0) - { + //if (domainOfExpertiseGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -317,7 +321,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (domainOfExpertiseGroup.Alias.Count > 0) - { + //if (domainOfExpertiseGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,13 +361,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); - if (domainOfExpertiseGroup.Definition.Count > 0) - { + //if (domainOfExpertiseGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -372,11 +376,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.Domain.Count > 0) - { + //if (domainOfExpertiseGroup.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - { + //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -411,11 +415,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertiseGroup.HyperLink.Count > 0) - { + //if (domainOfExpertiseGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -424,7 +428,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -521,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { writer.WriteStartArray("domain"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -589,6 +618,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index 5f129689c..5926b122d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); - if (domainOfExpertise.Alias.Count > 0) - { + //if (domainOfExpertise.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.Category.Count > 0) - { + //if (domainOfExpertise.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - if (domainOfExpertise.Definition.Count > 0) - { + //if (domainOfExpertise.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.HyperLink.Count > 0) - { + //if (domainOfExpertise.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); - if (domainOfExpertise.Alias.Count > 0) - { + //if (domainOfExpertise.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.Category.Count > 0) - { + //if (domainOfExpertise.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) @@ -168,13 +172,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - if (domainOfExpertise.Definition.Count > 0) - { + //if (domainOfExpertise.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedDomain.Count > 0) - { + //if (domainOfExpertise.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedPerson.Count > 0) - { + //if (domainOfExpertise.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.HyperLink.Count > 0) - { + //if (domainOfExpertise.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); - if (domainOfExpertise.Alias.Count > 0) - { + //if (domainOfExpertise.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,11 +254,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.Category.Count > 0) - { + //if (domainOfExpertise.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) @@ -263,13 +267,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - if (domainOfExpertise.Definition.Count > 0) - { + //if (domainOfExpertise.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedDomain.Count > 0) - { + //if (domainOfExpertise.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedPerson.Count > 0) - { + //if (domainOfExpertise.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -304,11 +308,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.HyperLink.Count > 0) - { + //if (domainOfExpertise.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -317,7 +321,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (domainOfExpertise.Alias.Count > 0) - { + //if (domainOfExpertise.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,11 +361,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.Category.Count > 0) - { + //if (domainOfExpertise.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) @@ -370,13 +374,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); - if (domainOfExpertise.Definition.Count > 0) - { + //if (domainOfExpertise.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedDomain.Count > 0) - { + //if (domainOfExpertise.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.ExcludedPerson.Count > 0) - { + //if (domainOfExpertise.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -411,11 +415,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (domainOfExpertise.HyperLink.Count > 0) - { + //if (domainOfExpertise.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -424,7 +428,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -503,6 +512,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -589,6 +618,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index 151de2db4..e5e8db51e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); - if (elementDefinition.Alias.Count > 0) - { + //if (elementDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Category.Count > 0) - { + //if (elementDefinition.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - if (elementDefinition.ContainedElement.Count > 0) - { + //if (elementDefinition.ContainedElement.Count > 0) + //{ writer.WriteStartArray("containedElement"u8); foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Definition.Count > 0) - { + //if (elementDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.HyperLink.Count > 0) - { + //if (elementDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -142,7 +146,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -151,8 +155,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - if (elementDefinition.Parameter.Count > 0) - { + //if (elementDefinition.Parameter.Count > 0) + //{ writer.WriteStartArray("parameter"u8); foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) @@ -161,11 +165,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ParameterGroup.Count > 0) - { + //if (elementDefinition.ParameterGroup.Count > 0) + //{ writer.WriteStartArray("parameterGroup"u8); foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) @@ -174,11 +178,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ReferencedElement.Count > 0) - { + //if (elementDefinition.ReferencedElement.Count > 0) + //{ writer.WriteStartArray("referencedElement"u8); foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) @@ -187,7 +191,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -197,8 +201,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); - if (elementDefinition.Alias.Count > 0) - { + //if (elementDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -207,11 +211,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Category.Count > 0) - { + //if (elementDefinition.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - if (elementDefinition.ContainedElement.Count > 0) - { + //if (elementDefinition.ContainedElement.Count > 0) + //{ writer.WriteStartArray("containedElement"u8); foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Definition.Count > 0) - { + //if (elementDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedDomain.Count > 0) - { + //if (elementDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -261,11 +265,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedPerson.Count > 0) - { + //if (elementDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -274,11 +278,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.HyperLink.Count > 0) - { + //if (elementDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -287,7 +291,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -298,8 +302,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - if (elementDefinition.Parameter.Count > 0) - { + //if (elementDefinition.Parameter.Count > 0) + //{ writer.WriteStartArray("parameter"u8); foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ParameterGroup.Count > 0) - { + //if (elementDefinition.ParameterGroup.Count > 0) + //{ writer.WriteStartArray("parameterGroup"u8); foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) @@ -321,11 +325,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ReferencedElement.Count > 0) - { + //if (elementDefinition.ReferencedElement.Count > 0) + //{ writer.WriteStartArray("referencedElement"u8); foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) @@ -334,7 +338,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -344,8 +348,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); - if (elementDefinition.Alias.Count > 0) - { + //if (elementDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -354,11 +358,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Category.Count > 0) - { + //if (elementDefinition.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) @@ -367,13 +371,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - if (elementDefinition.ContainedElement.Count > 0) - { + //if (elementDefinition.ContainedElement.Count > 0) + //{ writer.WriteStartArray("containedElement"u8); foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) @@ -382,11 +386,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Definition.Count > 0) - { + //if (elementDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -395,11 +399,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedDomain.Count > 0) - { + //if (elementDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -408,11 +412,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedPerson.Count > 0) - { + //if (elementDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -421,11 +425,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.HyperLink.Count > 0) - { + //if (elementDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -434,7 +438,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); - if (elementDefinition.OrganizationalParticipant.Count > 0) - { + //if (elementDefinition.OrganizationalParticipant.Count > 0) + //{ writer.WriteStartArray("organizationalParticipant"u8); foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) @@ -453,13 +457,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - if (elementDefinition.Parameter.Count > 0) - { + //if (elementDefinition.Parameter.Count > 0) + //{ writer.WriteStartArray("parameter"u8); foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) @@ -468,11 +472,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ParameterGroup.Count > 0) - { + //if (elementDefinition.ParameterGroup.Count > 0) + //{ writer.WriteStartArray("parameterGroup"u8); foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) @@ -481,11 +485,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ReferencedElement.Count > 0) - { + //if (elementDefinition.ReferencedElement.Count > 0) + //{ writer.WriteStartArray("referencedElement"u8); foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) @@ -494,7 +498,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -516,8 +520,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (elementDefinition.Alias.Count > 0) - { + //if (elementDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -526,11 +530,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Category.Count > 0) - { + //if (elementDefinition.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) @@ -539,13 +543,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); - if (elementDefinition.ContainedElement.Count > 0) - { + //if (elementDefinition.ContainedElement.Count > 0) + //{ writer.WriteStartArray("containedElement"u8); foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) @@ -554,11 +558,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.Definition.Count > 0) - { + //if (elementDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -567,11 +571,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedDomain.Count > 0) - { + //if (elementDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -580,11 +584,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ExcludedPerson.Count > 0) - { + //if (elementDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -593,11 +597,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.HyperLink.Count > 0) - { + //if (elementDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -606,7 +610,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -615,8 +619,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); - if (elementDefinition.OrganizationalParticipant.Count > 0) - { + //if (elementDefinition.OrganizationalParticipant.Count > 0) + //{ writer.WriteStartArray("organizationalParticipant"u8); foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) @@ -625,13 +629,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); - if (elementDefinition.Parameter.Count > 0) - { + //if (elementDefinition.Parameter.Count > 0) + //{ writer.WriteStartArray("parameter"u8); foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) @@ -640,11 +644,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ParameterGroup.Count > 0) - { + //if (elementDefinition.ParameterGroup.Count > 0) + //{ writer.WriteStartArray("parameterGroup"u8); foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) @@ -653,11 +657,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementDefinition.ReferencedElement.Count > 0) - { + //if (elementDefinition.ReferencedElement.Count > 0) + //{ writer.WriteStartArray("referencedElement"u8); foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) @@ -666,7 +670,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -720,6 +724,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -737,6 +746,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -772,6 +786,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListContainedElement && objectListContainedElement.Any()) { writer.WriteStartArray("containedElement"u8); @@ -789,6 +808,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -806,6 +830,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -823,6 +852,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -840,6 +874,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -911,6 +950,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) { writer.WriteStartArray("organizationalParticipant"u8); @@ -946,6 +990,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameter && objectListParameter.Any()) { writer.WriteStartArray("parameter"u8); @@ -963,6 +1012,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterGroup && objectListParameterGroup.Any()) { writer.WriteStartArray("parameterGroup"u8); @@ -980,6 +1034,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListReferencedElement && objectListReferencedElement.Any()) { writer.WriteStartArray("referencedElement"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index db327a9bb..68b0ac006 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); - if (elementUsage.Alias.Count > 0) - { + //if (elementUsage.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.Category.Count > 0) - { + //if (elementUsage.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - if (elementUsage.Definition.Count > 0) - { + //if (elementUsage.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,13 +120,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - if (elementUsage.ExcludeOption.Count > 0) - { + //if (elementUsage.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -131,11 +135,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.HyperLink.Count > 0) - { + //if (elementUsage.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -155,8 +159,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - if (elementUsage.ParameterOverride.Count > 0) - { + //if (elementUsage.ParameterOverride.Count > 0) + //{ writer.WriteStartArray("parameterOverride"u8); foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) @@ -165,7 +169,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -175,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); - if (elementUsage.Alias.Count > 0) - { + //if (elementUsage.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.Category.Count > 0) - { + //if (elementUsage.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) @@ -198,13 +202,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - if (elementUsage.Definition.Count > 0) - { + //if (elementUsage.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) @@ -213,13 +217,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - if (elementUsage.ExcludedDomain.Count > 0) - { + //if (elementUsage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -228,11 +232,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludedPerson.Count > 0) - { + //if (elementUsage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -241,11 +245,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludeOption.Count > 0) - { + //if (elementUsage.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.HyperLink.Count > 0) - { + //if (elementUsage.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -267,7 +271,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -280,8 +284,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - if (elementUsage.ParameterOverride.Count > 0) - { + //if (elementUsage.ParameterOverride.Count > 0) + //{ writer.WriteStartArray("parameterOverride"u8); foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) @@ -290,7 +294,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -300,8 +304,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); - if (elementUsage.Alias.Count > 0) - { + //if (elementUsage.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) @@ -310,11 +314,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.Category.Count > 0) - { + //if (elementUsage.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) @@ -323,13 +327,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - if (elementUsage.Definition.Count > 0) - { + //if (elementUsage.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) @@ -338,13 +342,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - if (elementUsage.ExcludedDomain.Count > 0) - { + //if (elementUsage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludedPerson.Count > 0) - { + //if (elementUsage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -366,11 +370,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludeOption.Count > 0) - { + //if (elementUsage.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -379,11 +383,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.HyperLink.Count > 0) - { + //if (elementUsage.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -392,7 +396,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -405,8 +409,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - if (elementUsage.ParameterOverride.Count > 0) - { + //if (elementUsage.ParameterOverride.Count > 0) + //{ writer.WriteStartArray("parameterOverride"u8); foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) @@ -415,7 +419,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -437,8 +441,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (elementUsage.Alias.Count > 0) - { + //if (elementUsage.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) @@ -447,11 +451,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.Category.Count > 0) - { + //if (elementUsage.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) @@ -460,13 +464,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); - if (elementUsage.Definition.Count > 0) - { + //if (elementUsage.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) @@ -475,13 +479,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); - if (elementUsage.ExcludedDomain.Count > 0) - { + //if (elementUsage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -490,11 +494,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludedPerson.Count > 0) - { + //if (elementUsage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -503,11 +507,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.ExcludeOption.Count > 0) - { + //if (elementUsage.ExcludeOption.Count > 0) + //{ writer.WriteStartArray("excludeOption"u8); foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) @@ -516,11 +520,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (elementUsage.HyperLink.Count > 0) - { + //if (elementUsage.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -529,7 +533,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -542,8 +546,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); - if (elementUsage.ParameterOverride.Count > 0) - { + //if (elementUsage.ParameterOverride.Count > 0) + //{ writer.WriteStartArray("parameterOverride"u8); foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) @@ -552,7 +556,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -606,6 +610,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -623,6 +632,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -658,6 +672,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -693,6 +712,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -710,6 +734,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -727,6 +756,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) { writer.WriteStartArray("excludeOption"u8); @@ -744,6 +778,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -851,6 +890,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterOverride && objectListParameterOverride.Any()) { writer.WriteStartArray("parameterOverride"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index 67c70cdf9..efba04dc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - if (emailAddress.ExcludedDomain.Count > 0) - { + //if (emailAddress.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (emailAddress.ExcludedPerson.Count > 0) - { + //if (emailAddress.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - if (emailAddress.ExcludedDomain.Count > 0) - { + //if (emailAddress.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (emailAddress.ExcludedPerson.Count > 0) - { + //if (emailAddress.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); - if (emailAddress.ExcludedDomain.Count > 0) - { + //if (emailAddress.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (emailAddress.ExcludedPerson.Count > 0) - { + //if (emailAddress.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index 3a8d69bcb..21cd14ec9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -96,11 +100,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -109,7 +113,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -152,11 +156,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -165,7 +169,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -211,8 +215,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -221,11 +225,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -234,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -375,6 +379,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -392,6 +401,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 4c9432f1f..91ecd65d9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataNote.Discussion.Count > 0) - { + //if (engineeringModelDataNote.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -96,11 +100,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -141,8 +145,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelDataNote.RelatedThing.Count > 0) - { + //if (engineeringModelDataNote.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -151,7 +155,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -167,8 +171,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataNote.Discussion.Count > 0) - { + //if (engineeringModelDataNote.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -177,11 +181,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -190,11 +194,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -203,7 +207,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -222,8 +226,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelDataNote.RelatedThing.Count > 0) - { + //if (engineeringModelDataNote.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -232,7 +236,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -261,8 +265,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModelDataNote.Discussion.Count > 0) - { + //if (engineeringModelDataNote.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedDomain.Count > 0) - { + //if (engineeringModelDataNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -284,11 +288,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelDataNote.ExcludedPerson.Count > 0) - { + //if (engineeringModelDataNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -297,7 +301,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -316,8 +320,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelDataNote.RelatedThing.Count > 0) - { + //if (engineeringModelDataNote.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -326,7 +330,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -450,6 +454,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -467,6 +476,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -484,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -573,6 +592,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index f4376d3ba..9d86edd9f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - if (engineeringModel.CommonFileStore.Count > 0) - { + //if (engineeringModel.CommonFileStore.Count > 0) + //{ writer.WriteStartArray("commonFileStore"u8); foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) @@ -90,15 +94,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - if (engineeringModel.Iteration.Count > 0) - { + //if (engineeringModel.Iteration.Count > 0) + //{ writer.WriteStartArray("iteration"u8); foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) @@ -107,13 +111,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModel.LogEntry.Count > 0) - { + //if (engineeringModel.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModel.RevisionNumber); @@ -130,8 +134,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); - if (engineeringModel.Book.Count > 0) - { + //if (engineeringModel.Book.Count > 0) + //{ writer.WriteStartArray("book"u8); foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) @@ -140,13 +144,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - if (engineeringModel.CommonFileStore.Count > 0) - { + //if (engineeringModel.CommonFileStore.Count > 0) + //{ writer.WriteStartArray("commonFileStore"u8); foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - if (engineeringModel.ExcludedDomain.Count > 0) - { + //if (engineeringModel.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ExcludedPerson.Count > 0) - { + //if (engineeringModel.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.GenericNote.Count > 0) - { + //if (engineeringModel.GenericNote.Count > 0) + //{ writer.WriteStartArray("genericNote"u8); foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) @@ -196,13 +200,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - if (engineeringModel.Iteration.Count > 0) - { + //if (engineeringModel.Iteration.Count > 0) + //{ writer.WriteStartArray("iteration"u8); foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) @@ -211,13 +215,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModel.LogEntry.Count > 0) - { + //if (engineeringModel.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -226,11 +230,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ModellingAnnotation.Count > 0) - { + //if (engineeringModel.ModellingAnnotation.Count > 0) + //{ writer.WriteStartArray("modellingAnnotation"u8); foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -239,7 +243,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -249,8 +253,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); - if (engineeringModel.Book.Count > 0) - { + //if (engineeringModel.Book.Count > 0) + //{ writer.WriteStartArray("book"u8); foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) @@ -259,13 +263,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - if (engineeringModel.CommonFileStore.Count > 0) - { + //if (engineeringModel.CommonFileStore.Count > 0) + //{ writer.WriteStartArray("commonFileStore"u8); foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) @@ -274,13 +278,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - if (engineeringModel.ExcludedDomain.Count > 0) - { + //if (engineeringModel.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -289,11 +293,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ExcludedPerson.Count > 0) - { + //if (engineeringModel.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -302,11 +306,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.GenericNote.Count > 0) - { + //if (engineeringModel.GenericNote.Count > 0) + //{ writer.WriteStartArray("genericNote"u8); foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) @@ -315,13 +319,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - if (engineeringModel.Iteration.Count > 0) - { + //if (engineeringModel.Iteration.Count > 0) + //{ writer.WriteStartArray("iteration"u8); foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) @@ -330,13 +334,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModel.LogEntry.Count > 0) - { + //if (engineeringModel.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -345,11 +349,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ModellingAnnotation.Count > 0) - { + //if (engineeringModel.ModellingAnnotation.Count > 0) + //{ writer.WriteStartArray("modellingAnnotation"u8); foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -358,7 +362,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -380,8 +384,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModel.Book.Count > 0) - { + //if (engineeringModel.Book.Count > 0) + //{ writer.WriteStartArray("book"u8); foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) @@ -390,13 +394,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); - if (engineeringModel.CommonFileStore.Count > 0) - { + //if (engineeringModel.CommonFileStore.Count > 0) + //{ writer.WriteStartArray("commonFileStore"u8); foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) @@ -405,13 +409,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); - if (engineeringModel.ExcludedDomain.Count > 0) - { + //if (engineeringModel.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -420,11 +424,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ExcludedPerson.Count > 0) - { + //if (engineeringModel.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -433,11 +437,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.GenericNote.Count > 0) - { + //if (engineeringModel.GenericNote.Count > 0) + //{ writer.WriteStartArray("genericNote"u8); foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) @@ -446,13 +450,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); - if (engineeringModel.Iteration.Count > 0) - { + //if (engineeringModel.Iteration.Count > 0) + //{ writer.WriteStartArray("iteration"u8); foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) @@ -461,13 +465,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (engineeringModel.LogEntry.Count > 0) - { + //if (engineeringModel.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -476,11 +480,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModel.ModellingAnnotation.Count > 0) - { + //if (engineeringModel.ModellingAnnotation.Count > 0) + //{ writer.WriteStartArray("modellingAnnotation"u8); foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -489,7 +493,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -543,6 +547,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBook && objectListBook.Any()) { writer.WriteStartArray("book"u8); @@ -578,6 +587,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCommonFileStore && objectListCommonFileStore.Any()) { writer.WriteStartArray("commonFileStore"u8); @@ -613,6 +627,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -630,6 +649,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -647,6 +671,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGenericNote && objectListGenericNote.Any()) { writer.WriteStartArray("genericNote"u8); @@ -682,6 +711,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListIteration && objectListIteration.Any()) { writer.WriteStartArray("iteration"u8); @@ -717,6 +751,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) { writer.WriteStartArray("logEntry"u8); @@ -734,6 +773,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListModellingAnnotation && objectListModellingAnnotation.Any()) { writer.WriteStartArray("modellingAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index 49119c364..517337d6d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); - if (engineeringModelSetup.ActiveDomain.Count > 0) - { + //if (engineeringModelSetup.ActiveDomain.Count > 0) + //{ writer.WriteStartArray("activeDomain"u8); foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.Alias.Count > 0) - { + //if (engineeringModelSetup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - if (engineeringModelSetup.Definition.Count > 0) - { + //if (engineeringModelSetup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,13 +120,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - if (engineeringModelSetup.HyperLink.Count > 0) - { + //if (engineeringModelSetup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,13 +135,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - if (engineeringModelSetup.IterationSetup.Count > 0) - { + //if (engineeringModelSetup.IterationSetup.Count > 0) + //{ writer.WriteStartArray("iterationSetup"u8); foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) @@ -146,15 +150,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - if (engineeringModelSetup.Participant.Count > 0) - { + //if (engineeringModelSetup.Participant.Count > 0) + //{ writer.WriteStartArray("participant"u8); foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) @@ -163,11 +167,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.RequiredRdl.Count > 0) - { + //if (engineeringModelSetup.RequiredRdl.Count > 0) + //{ writer.WriteStartArray("requiredRdl"u8); foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) @@ -176,7 +180,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -199,8 +203,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); - if (engineeringModelSetup.ActiveDomain.Count > 0) - { + //if (engineeringModelSetup.ActiveDomain.Count > 0) + //{ writer.WriteStartArray("activeDomain"u8); foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.Alias.Count > 0) - { + //if (engineeringModelSetup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -222,13 +226,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); - if (engineeringModelSetup.Definition.Count > 0) - { + //if (engineeringModelSetup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -237,13 +241,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - if (engineeringModelSetup.ExcludedDomain.Count > 0) - { + //if (engineeringModelSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.ExcludedPerson.Count > 0) - { + //if (engineeringModelSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.HyperLink.Count > 0) - { + //if (engineeringModelSetup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -278,13 +282,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - if (engineeringModelSetup.IterationSetup.Count > 0) - { + //if (engineeringModelSetup.IterationSetup.Count > 0) + //{ writer.WriteStartArray("iterationSetup"u8); foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) @@ -293,7 +297,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -302,8 +306,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - if (engineeringModelSetup.Participant.Count > 0) - { + //if (engineeringModelSetup.Participant.Count > 0) + //{ writer.WriteStartArray("participant"u8); foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) @@ -312,11 +316,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.RequiredRdl.Count > 0) - { + //if (engineeringModelSetup.RequiredRdl.Count > 0) + //{ writer.WriteStartArray("requiredRdl"u8); foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) @@ -325,7 +329,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -348,8 +352,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); - if (engineeringModelSetup.ActiveDomain.Count > 0) - { + //if (engineeringModelSetup.ActiveDomain.Count > 0) + //{ writer.WriteStartArray("activeDomain"u8); foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) @@ -358,11 +362,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.Alias.Count > 0) - { + //if (engineeringModelSetup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -371,7 +375,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelSetup.Definition.Count > 0) - { + //if (engineeringModelSetup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -396,13 +400,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - if (engineeringModelSetup.ExcludedDomain.Count > 0) - { + //if (engineeringModelSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -411,11 +415,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.ExcludedPerson.Count > 0) - { + //if (engineeringModelSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -424,11 +428,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.HyperLink.Count > 0) - { + //if (engineeringModelSetup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -437,13 +441,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - if (engineeringModelSetup.IterationSetup.Count > 0) - { + //if (engineeringModelSetup.IterationSetup.Count > 0) + //{ writer.WriteStartArray("iterationSetup"u8); foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) @@ -452,7 +456,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -461,8 +465,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - if (engineeringModelSetup.OrganizationalParticipant.Count > 0) - { + //if (engineeringModelSetup.OrganizationalParticipant.Count > 0) + //{ writer.WriteStartArray("organizationalParticipant"u8); foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) @@ -471,11 +475,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.Participant.Count > 0) - { + //if (engineeringModelSetup.Participant.Count > 0) + //{ writer.WriteStartArray("participant"u8); foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) @@ -484,11 +488,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.RequiredRdl.Count > 0) - { + //if (engineeringModelSetup.RequiredRdl.Count > 0) + //{ writer.WriteStartArray("requiredRdl"u8); foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) @@ -497,7 +501,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -522,8 +526,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); - if (engineeringModelSetup.ActiveDomain.Count > 0) - { + //if (engineeringModelSetup.ActiveDomain.Count > 0) + //{ writer.WriteStartArray("activeDomain"u8); foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) @@ -532,7 +536,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("actor"u8); @@ -545,8 +549,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelSetup.Alias.Count > 0) - { + //if (engineeringModelSetup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -555,7 +559,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); @@ -570,8 +574,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (engineeringModelSetup.Definition.Count > 0) - { + //if (engineeringModelSetup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -580,13 +584,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); - if (engineeringModelSetup.ExcludedDomain.Count > 0) - { + //if (engineeringModelSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -595,11 +599,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.ExcludedPerson.Count > 0) - { + //if (engineeringModelSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -608,11 +612,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.HyperLink.Count > 0) - { + //if (engineeringModelSetup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -621,13 +625,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); - if (engineeringModelSetup.IterationSetup.Count > 0) - { + //if (engineeringModelSetup.IterationSetup.Count > 0) + //{ writer.WriteStartArray("iterationSetup"u8); foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) @@ -636,7 +640,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -645,8 +649,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); - if (engineeringModelSetup.OrganizationalParticipant.Count > 0) - { + //if (engineeringModelSetup.OrganizationalParticipant.Count > 0) + //{ writer.WriteStartArray("organizationalParticipant"u8); foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) @@ -655,11 +659,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.Participant.Count > 0) - { + //if (engineeringModelSetup.Participant.Count > 0) + //{ writer.WriteStartArray("participant"u8); foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) @@ -668,11 +672,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (engineeringModelSetup.RequiredRdl.Count > 0) - { + //if (engineeringModelSetup.RequiredRdl.Count > 0) + //{ writer.WriteStartArray("requiredRdl"u8); foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) @@ -681,7 +685,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -730,6 +734,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListActiveDomain && objectListActiveDomain.Any()) { writer.WriteStartArray("activeDomain"u8); @@ -765,6 +774,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -818,6 +832,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -853,6 +872,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -870,6 +894,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -887,6 +916,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -922,6 +956,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListIterationSetup && objectListIterationSetup.Any()) { writer.WriteStartArray("iterationSetup"u8); @@ -993,6 +1032,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) { writer.WriteStartArray("organizationalParticipant"u8); @@ -1010,6 +1054,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParticipant && objectListParticipant.Any()) { writer.WriteStartArray("participant"u8); @@ -1027,6 +1076,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRequiredRdl && objectListRequiredRdl.Any()) { writer.WriteStartArray("requiredRdl"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index e89498ed5..7ece57e40 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); - if (enumerationParameterType.Alias.Count > 0) - { + //if (enumerationParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - if (enumerationParameterType.Category.Count > 0) - { + //if (enumerationParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,13 +107,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - if (enumerationParameterType.Definition.Count > 0) - { + //if (enumerationParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.HyperLink.Count > 0) - { + //if (enumerationParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -146,8 +150,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); - if (enumerationParameterType.ValueDefinition.Count > 0) - { + //if (enumerationParameterType.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) @@ -156,14 +160,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); - if (enumerationParameterType.Alias.Count > 0) - { + //if (enumerationParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -172,13 +176,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - if (enumerationParameterType.Category.Count > 0) - { + //if (enumerationParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -187,13 +191,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - if (enumerationParameterType.Definition.Count > 0) - { + //if (enumerationParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -202,11 +206,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedDomain.Count > 0) - { + //if (enumerationParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -215,11 +219,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedPerson.Count > 0) - { + //if (enumerationParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -228,11 +232,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.HyperLink.Count > 0) - { + //if (enumerationParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -241,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -258,8 +262,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); - if (enumerationParameterType.ValueDefinition.Count > 0) - { + //if (enumerationParameterType.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) @@ -268,14 +272,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); - if (enumerationParameterType.Alias.Count > 0) - { + //if (enumerationParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -284,13 +288,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - if (enumerationParameterType.Category.Count > 0) - { + //if (enumerationParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -299,13 +303,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - if (enumerationParameterType.Definition.Count > 0) - { + //if (enumerationParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedDomain.Count > 0) - { + //if (enumerationParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedPerson.Count > 0) - { + //if (enumerationParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.HyperLink.Count > 0) - { + //if (enumerationParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -353,7 +357,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -372,8 +376,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); - if (enumerationParameterType.ValueDefinition.Count > 0) - { + //if (enumerationParameterType.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) @@ -382,7 +386,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -398,8 +402,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (enumerationParameterType.Alias.Count > 0) - { + //if (enumerationParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -408,13 +412,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); - if (enumerationParameterType.Category.Count > 0) - { + //if (enumerationParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -423,13 +427,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); - if (enumerationParameterType.Definition.Count > 0) - { + //if (enumerationParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -438,11 +442,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedDomain.Count > 0) - { + //if (enumerationParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -451,11 +455,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.ExcludedPerson.Count > 0) - { + //if (enumerationParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -464,11 +468,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationParameterType.HyperLink.Count > 0) - { + //if (enumerationParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -477,7 +481,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -496,8 +500,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); - if (enumerationParameterType.ValueDefinition.Count > 0) - { + //if (enumerationParameterType.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) @@ -506,7 +510,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -554,6 +558,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -589,6 +598,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -624,6 +638,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -641,6 +660,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -658,6 +682,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -675,6 +704,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -836,6 +870,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 935d060a1..2bd549351 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); - if (enumerationValueDefinition.Alias.Count > 0) - { + //if (enumerationValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - if (enumerationValueDefinition.Definition.Count > 0) - { + //if (enumerationValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.HyperLink.Count > 0) - { + //if (enumerationValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -130,8 +134,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); - if (enumerationValueDefinition.Alias.Count > 0) - { + //if (enumerationValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -140,13 +144,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - if (enumerationValueDefinition.Definition.Count > 0) - { + //if (enumerationValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedDomain.Count > 0) - { + //if (enumerationValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedPerson.Count > 0) - { + //if (enumerationValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.HyperLink.Count > 0) - { + //if (enumerationValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -210,8 +214,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); - if (enumerationValueDefinition.Alias.Count > 0) - { + //if (enumerationValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - if (enumerationValueDefinition.Definition.Count > 0) - { + //if (enumerationValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedDomain.Count > 0) - { + //if (enumerationValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedPerson.Count > 0) - { + //if (enumerationValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -261,11 +265,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.HyperLink.Count > 0) - { + //if (enumerationValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -274,7 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -302,8 +306,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (enumerationValueDefinition.Alias.Count > 0) - { + //if (enumerationValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -312,13 +316,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); - if (enumerationValueDefinition.Definition.Count > 0) - { + //if (enumerationValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedDomain.Count > 0) - { + //if (enumerationValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.ExcludedPerson.Count > 0) - { + //if (enumerationValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (enumerationValueDefinition.HyperLink.Count > 0) - { + //if (enumerationValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -366,7 +370,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -426,6 +430,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -461,6 +470,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -478,6 +492,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -495,6 +514,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -512,6 +536,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index fad0793c8..99bac48c6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -84,8 +88,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - if (exclusiveOrExpression.Term.Count > 0) - { + //if (exclusiveOrExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -94,7 +98,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -102,8 +106,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - if (exclusiveOrExpression.ExcludedDomain.Count > 0) - { + //if (exclusiveOrExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -112,11 +116,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (exclusiveOrExpression.ExcludedPerson.Count > 0) - { + //if (exclusiveOrExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -125,7 +129,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - if (exclusiveOrExpression.Term.Count > 0) - { + //if (exclusiveOrExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -152,8 +156,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - if (exclusiveOrExpression.ExcludedDomain.Count > 0) - { + //if (exclusiveOrExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -162,11 +166,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (exclusiveOrExpression.ExcludedPerson.Count > 0) - { + //if (exclusiveOrExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -175,7 +179,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -184,8 +188,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - if (exclusiveOrExpression.Term.Count > 0) - { + //if (exclusiveOrExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); @@ -215,8 +219,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); - if (exclusiveOrExpression.ExcludedDomain.Count > 0) - { + //if (exclusiveOrExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -225,11 +229,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (exclusiveOrExpression.ExcludedPerson.Count > 0) - { + //if (exclusiveOrExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -238,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -247,8 +251,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); - if (exclusiveOrExpression.Term.Count > 0) - { + //if (exclusiveOrExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -257,7 +261,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); @@ -325,6 +329,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -342,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -413,6 +427,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { writer.WriteStartArray("term"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 51c1a7546..2c469510a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - if (externalIdentifierMap.Correspondence.Count > 0) - { + //if (externalIdentifierMap.Correspondence.Count > 0) + //{ writer.WriteStartArray("correspondence"u8); foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) @@ -90,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalFormat"u8); @@ -123,8 +127,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - if (externalIdentifierMap.Correspondence.Count > 0) - { + //if (externalIdentifierMap.Correspondence.Count > 0) + //{ writer.WriteStartArray("correspondence"u8); foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) @@ -133,11 +137,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedDomain.Count > 0) - { + //if (externalIdentifierMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -146,11 +150,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedPerson.Count > 0) - { + //if (externalIdentifierMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -159,7 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalFormat"u8); @@ -194,8 +198,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - if (externalIdentifierMap.Correspondence.Count > 0) - { + //if (externalIdentifierMap.Correspondence.Count > 0) + //{ writer.WriteStartArray("correspondence"u8); foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) @@ -204,11 +208,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedDomain.Count > 0) - { + //if (externalIdentifierMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedPerson.Count > 0) - { + //if (externalIdentifierMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -230,7 +234,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalFormat"u8); @@ -278,8 +282,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); - if (externalIdentifierMap.Correspondence.Count > 0) - { + //if (externalIdentifierMap.Correspondence.Count > 0) + //{ writer.WriteStartArray("correspondence"u8); foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) @@ -288,11 +292,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedDomain.Count > 0) - { + //if (externalIdentifierMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -301,11 +305,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (externalIdentifierMap.ExcludedPerson.Count > 0) - { + //if (externalIdentifierMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -314,7 +318,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalFormat"u8); @@ -409,6 +413,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCorrespondence && objectListCorrespondence.Any()) { writer.WriteStartArray("correspondence"u8); @@ -426,6 +435,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -443,6 +457,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 511f72b51..1a626a01b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - if (fileRevision.FileType.Count > 0) - { + //if (fileRevision.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) @@ -107,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - if (fileRevision.ExcludedDomain.Count > 0) - { + //if (fileRevision.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -148,11 +152,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.ExcludedPerson.Count > 0) - { + //if (fileRevision.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -161,11 +165,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.FileType.Count > 0) - { + //if (fileRevision.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) @@ -174,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -207,8 +211,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - if (fileRevision.ExcludedDomain.Count > 0) - { + //if (fileRevision.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.ExcludedPerson.Count > 0) - { + //if (fileRevision.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -230,11 +234,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.FileType.Count > 0) - { + //if (fileRevision.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) @@ -243,7 +247,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -289,8 +293,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); - if (fileRevision.ExcludedDomain.Count > 0) - { + //if (fileRevision.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -299,11 +303,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.ExcludedPerson.Count > 0) - { + //if (fileRevision.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -312,11 +316,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileRevision.FileType.Count > 0) - { + //if (fileRevision.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) @@ -325,7 +329,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -473,6 +477,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -490,6 +499,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -507,6 +521,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { writer.WriteStartArray("fileType"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 7cd4bbe62..6838b588a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); - if (file.Category.Count > 0) - { + //if (file.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - if (file.FileRevision.Count > 0) - { + //if (file.FileRevision.Count > 0) + //{ writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -126,8 +130,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); - if (file.Category.Count > 0) - { + //if (file.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -136,13 +140,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - if (file.ExcludedDomain.Count > 0) - { + //if (file.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -151,11 +155,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.ExcludedPerson.Count > 0) - { + //if (file.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -164,11 +168,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.FileRevision.Count > 0) - { + //if (file.FileRevision.Count > 0) + //{ writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -177,7 +181,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -202,8 +206,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); - if (file.Category.Count > 0) - { + //if (file.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -212,13 +216,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - if (file.ExcludedDomain.Count > 0) - { + //if (file.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -227,11 +231,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.ExcludedPerson.Count > 0) - { + //if (file.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -240,11 +244,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.FileRevision.Count > 0) - { + //if (file.FileRevision.Count > 0) + //{ writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -253,7 +257,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -290,8 +294,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (file.Category.Count > 0) - { + //if (file.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) @@ -300,13 +304,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); - if (file.ExcludedDomain.Count > 0) - { + //if (file.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -315,11 +319,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.ExcludedPerson.Count > 0) - { + //if (file.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -328,11 +332,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (file.FileRevision.Count > 0) - { + //if (file.FileRevision.Count > 0) + //{ writer.WriteStartArray("fileRevision"u8); foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) @@ -341,7 +345,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); @@ -410,6 +414,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -445,6 +454,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -462,6 +476,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -479,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFileRevision && objectListFileRevision.Any()) { writer.WriteStartArray("fileRevision"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 8a016389b..9399482a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); - if (fileType.Alias.Count > 0) - { + //if (fileType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.Category.Count > 0) - { + //if (fileType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - if (fileType.Definition.Count > 0) - { + //if (fileType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,13 +120,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - if (fileType.HyperLink.Count > 0) - { + //if (fileType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); - if (fileType.Alias.Count > 0) - { + //if (fileType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.Category.Count > 0) - { + //if (fileType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - if (fileType.Definition.Count > 0) - { + //if (fileType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedDomain.Count > 0) - { + //if (fileType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedPerson.Count > 0) - { + //if (fileType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,13 +215,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - if (fileType.HyperLink.Count > 0) - { + //if (fileType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -226,7 +230,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); - if (fileType.Alias.Count > 0) - { + //if (fileType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.Category.Count > 0) - { + //if (fileType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - if (fileType.Definition.Count > 0) - { + //if (fileType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedDomain.Count > 0) - { + //if (fileType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedPerson.Count > 0) - { + //if (fileType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,13 +312,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - if (fileType.HyperLink.Count > 0) - { + //if (fileType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -323,7 +327,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (fileType.Alias.Count > 0) - { + //if (fileType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.Category.Count > 0) - { + //if (fileType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); - if (fileType.Definition.Count > 0) - { + //if (fileType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedDomain.Count > 0) - { + //if (fileType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (fileType.ExcludedPerson.Count > 0) - { + //if (fileType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,13 +421,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); - if (fileType.HyperLink.Count > 0) - { + //if (fileType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -432,7 +436,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -615,6 +644,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index ec77511fa..77764572a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -123,8 +127,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - if (folder.ExcludedDomain.Count > 0) - { + //if (folder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -133,11 +137,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (folder.ExcludedPerson.Count > 0) - { + //if (folder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -146,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -179,8 +183,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - if (folder.ExcludedDomain.Count > 0) - { + //if (folder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -189,11 +193,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (folder.ExcludedPerson.Count > 0) - { + //if (folder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -248,8 +252,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); - if (folder.ExcludedDomain.Count > 0) - { + //if (folder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -258,11 +262,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (folder.ExcludedPerson.Count > 0) - { + //if (folder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -271,7 +275,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -403,6 +407,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -420,6 +429,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index f7c3b038f..7883f9294 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); - if (glossary.Alias.Count > 0) - { + //if (glossary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.Category.Count > 0) - { + //if (glossary.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - if (glossary.Definition.Count > 0) - { + //if (glossary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.HyperLink.Count > 0) - { + //if (glossary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - if (glossary.Term.Count > 0) - { + //if (glossary.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) @@ -152,14 +156,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); - if (glossary.Alias.Count > 0) - { + //if (glossary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.Category.Count > 0) - { + //if (glossary.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) @@ -181,13 +185,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - if (glossary.Definition.Count > 0) - { + //if (glossary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedDomain.Count > 0) - { + //if (glossary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedPerson.Count > 0) - { + //if (glossary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.HyperLink.Count > 0) - { + //if (glossary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -235,7 +239,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -250,8 +254,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - if (glossary.Term.Count > 0) - { + //if (glossary.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) @@ -260,14 +264,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); - if (glossary.Alias.Count > 0) - { + //if (glossary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.Category.Count > 0) - { + //if (glossary.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) @@ -289,13 +293,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - if (glossary.Definition.Count > 0) - { + //if (glossary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -304,11 +308,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedDomain.Count > 0) - { + //if (glossary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -317,11 +321,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedPerson.Count > 0) - { + //if (glossary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -330,11 +334,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.HyperLink.Count > 0) - { + //if (glossary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -343,7 +347,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -358,8 +362,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - if (glossary.Term.Count > 0) - { + //if (glossary.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) @@ -368,7 +372,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (glossary.Alias.Count > 0) - { + //if (glossary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -396,11 +400,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.Category.Count > 0) - { + //if (glossary.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) @@ -409,13 +413,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); - if (glossary.Definition.Count > 0) - { + //if (glossary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -424,11 +428,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedDomain.Count > 0) - { + //if (glossary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -437,11 +441,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.ExcludedPerson.Count > 0) - { + //if (glossary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -450,11 +454,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (glossary.HyperLink.Count > 0) - { + //if (glossary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -463,7 +467,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -478,8 +482,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); - if (glossary.Term.Count > 0) - { + //if (glossary.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) @@ -488,7 +492,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); @@ -538,6 +542,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -555,6 +564,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -590,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -607,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -624,6 +648,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -641,6 +670,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -766,6 +800,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { writer.WriteStartArray("term"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 7d3d8eb46..a8ba8576d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); - if (goal.Alias.Count > 0) - { + //if (goal.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.Category.Count > 0) - { + //if (goal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - if (goal.Definition.Count > 0) - { + //if (goal.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedDomain.Count > 0) - { + //if (goal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedPerson.Count > 0) - { + //if (goal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.HyperLink.Count > 0) - { + //if (goal.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); - if (goal.Alias.Count > 0) - { + //if (goal.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.Category.Count > 0) - { + //if (goal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) @@ -194,13 +198,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - if (goal.Definition.Count > 0) - { + //if (goal.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedDomain.Count > 0) - { + //if (goal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedPerson.Count > 0) - { + //if (goal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.HyperLink.Count > 0) - { + //if (goal.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -248,7 +252,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (goal.Alias.Count > 0) - { + //if (goal.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) @@ -286,11 +290,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.Category.Count > 0) - { + //if (goal.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) @@ -299,13 +303,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); - if (goal.Definition.Count > 0) - { + //if (goal.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedDomain.Count > 0) - { + //if (goal.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.ExcludedPerson.Count > 0) - { + //if (goal.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (goal.HyperLink.Count > 0) - { + //if (goal.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -353,7 +357,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -413,6 +417,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -430,6 +439,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -465,6 +479,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -482,6 +501,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -499,6 +523,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -516,6 +545,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index e78ce8d2c..28c2c3100 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - if (hyperLink.ExcludedDomain.Count > 0) - { + //if (hyperLink.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (hyperLink.ExcludedPerson.Count > 0) - { + //if (hyperLink.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - if (hyperLink.ExcludedDomain.Count > 0) - { + //if (hyperLink.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -150,11 +154,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (hyperLink.ExcludedPerson.Count > 0) - { + //if (hyperLink.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -163,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -196,8 +200,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); - if (hyperLink.ExcludedDomain.Count > 0) - { + //if (hyperLink.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (hyperLink.ExcludedPerson.Count > 0) - { + //if (hyperLink.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -219,7 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -315,6 +319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -332,6 +341,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index d535f6fe2..b97a71551 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - if (idCorrespondence.ExcludedDomain.Count > 0) - { + //if (idCorrespondence.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (idCorrespondence.ExcludedPerson.Count > 0) - { + //if (idCorrespondence.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - if (idCorrespondence.ExcludedDomain.Count > 0) - { + //if (idCorrespondence.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (idCorrespondence.ExcludedPerson.Count > 0) - { + //if (idCorrespondence.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); - if (idCorrespondence.ExcludedDomain.Count > 0) - { + //if (idCorrespondence.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (idCorrespondence.ExcludedPerson.Count > 0) - { + //if (idCorrespondence.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index 1162a381a..ab578f69f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) - { + //if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) - { + //if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); @@ -143,8 +147,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); - if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) - { + //if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -153,11 +157,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) - { + //if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -166,7 +170,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); @@ -253,6 +257,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -270,6 +279,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index e2e465e24..6df6984b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); - if (intervalScale.Alias.Count > 0) - { + //if (intervalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - if (intervalScale.Definition.Count > 0) - { + //if (intervalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.HyperLink.Count > 0) - { + //if (intervalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - if (intervalScale.MappingToReferenceScale.Count > 0) - { + //if (intervalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -158,8 +162,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - if (intervalScale.ValueDefinition.Count > 0) - { + //if (intervalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -168,14 +172,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); - if (intervalScale.Alias.Count > 0) - { + //if (intervalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -184,13 +188,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - if (intervalScale.Definition.Count > 0) - { + //if (intervalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -199,11 +203,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedDomain.Count > 0) - { + //if (intervalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -212,11 +216,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedPerson.Count > 0) - { + //if (intervalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -225,11 +229,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.HyperLink.Count > 0) - { + //if (intervalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -238,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -249,8 +253,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - if (intervalScale.MappingToReferenceScale.Count > 0) - { + //if (intervalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -259,7 +263,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -282,8 +286,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - if (intervalScale.ValueDefinition.Count > 0) - { + //if (intervalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -292,14 +296,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); - if (intervalScale.Alias.Count > 0) - { + //if (intervalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -308,13 +312,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - if (intervalScale.Definition.Count > 0) - { + //if (intervalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -323,11 +327,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedDomain.Count > 0) - { + //if (intervalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -336,11 +340,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedPerson.Count > 0) - { + //if (intervalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -349,11 +353,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.HyperLink.Count > 0) - { + //if (intervalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -362,7 +366,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -373,8 +377,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - if (intervalScale.MappingToReferenceScale.Count > 0) - { + //if (intervalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -383,7 +387,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -408,8 +412,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - if (intervalScale.ValueDefinition.Count > 0) - { + //if (intervalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -418,7 +422,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -434,8 +438,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (intervalScale.Alias.Count > 0) - { + //if (intervalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -444,13 +448,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); - if (intervalScale.Definition.Count > 0) - { + //if (intervalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -459,11 +463,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedDomain.Count > 0) - { + //if (intervalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -472,11 +476,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.ExcludedPerson.Count > 0) - { + //if (intervalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -485,11 +489,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (intervalScale.HyperLink.Count > 0) - { + //if (intervalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -498,7 +502,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -509,8 +513,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); - if (intervalScale.MappingToReferenceScale.Count > 0) - { + //if (intervalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -519,7 +523,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -544,8 +548,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); - if (intervalScale.ValueDefinition.Count > 0) - { + //if (intervalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -554,7 +558,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -602,6 +606,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -637,6 +646,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -654,6 +668,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -671,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -688,6 +712,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -777,6 +806,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { writer.WriteStartArray("mappingToReferenceScale"u8); @@ -992,6 +1026,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index 6dea82aa3..5f192e057 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); - if (iteration.ActualFiniteStateList.Count > 0) - { + //if (iteration.ActualFiniteStateList.Count > 0) + //{ writer.WriteStartArray("actualFiniteStateList"u8); foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -103,8 +107,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.DomainFileStore.Count > 0) - { + //if (iteration.DomainFileStore.Count > 0) + //{ writer.WriteStartArray("domainFileStore"u8); foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) @@ -113,11 +117,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Element.Count > 0) - { + //if (iteration.Element.Count > 0) + //{ writer.WriteStartArray("element"u8); foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) @@ -126,11 +130,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExternalIdentifierMap.Count > 0) - { + //if (iteration.ExternalIdentifierMap.Count > 0) + //{ writer.WriteStartArray("externalIdentifierMap"u8); foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) @@ -139,15 +143,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); writer.WritePropertyName("iterationSetup"u8); writer.WriteStringValue(iteration.IterationSetup); - if (iteration.Option.Count > 0) - { + //if (iteration.Option.Count > 0) + //{ writer.WriteStartArray("option"u8); foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) @@ -156,11 +160,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.PossibleFiniteStateList.Count > 0) - { + //if (iteration.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -169,11 +173,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Publication.Count > 0) - { + //if (iteration.Publication.Count > 0) + //{ writer.WriteStartArray("publication"u8); foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) @@ -182,11 +186,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Relationship.Count > 0) - { + //if (iteration.Relationship.Count > 0) + //{ writer.WriteStartArray("relationship"u8); foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) @@ -195,11 +199,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.RequirementsSpecification.Count > 0) - { + //if (iteration.RequirementsSpecification.Count > 0) + //{ writer.WriteStartArray("requirementsSpecification"u8); foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) @@ -208,13 +212,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - if (iteration.RuleVerificationList.Count > 0) - { + //if (iteration.RuleVerificationList.Count > 0) + //{ writer.WriteStartArray("ruleVerificationList"u8); foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) @@ -223,7 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("sourceIterationIid"u8); @@ -251,8 +255,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); - if (iteration.ActualFiniteStateList.Count > 0) - { + //if (iteration.ActualFiniteStateList.Count > 0) + //{ writer.WriteStartArray("actualFiniteStateList"u8); foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.DiagramCanvas.Count > 0) - { + //if (iteration.DiagramCanvas.Count > 0) + //{ writer.WriteStartArray("diagramCanvas"u8); foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) @@ -286,11 +290,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.DomainFileStore.Count > 0) - { + //if (iteration.DomainFileStore.Count > 0) + //{ writer.WriteStartArray("domainFileStore"u8); foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) @@ -299,11 +303,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Element.Count > 0) - { + //if (iteration.Element.Count > 0) + //{ writer.WriteStartArray("element"u8); foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) @@ -312,11 +316,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedDomain.Count > 0) - { + //if (iteration.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -325,11 +329,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedPerson.Count > 0) - { + //if (iteration.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -338,11 +342,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExternalIdentifierMap.Count > 0) - { + //if (iteration.ExternalIdentifierMap.Count > 0) + //{ writer.WriteStartArray("externalIdentifierMap"u8); foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) @@ -351,11 +355,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Goal.Count > 0) - { + //if (iteration.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) @@ -364,7 +368,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -373,8 +377,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (iteration.Option.Count > 0) - { + //if (iteration.Option.Count > 0) + //{ writer.WriteStartArray("option"u8); foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) @@ -383,11 +387,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.PossibleFiniteStateList.Count > 0) - { + //if (iteration.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -396,11 +400,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Publication.Count > 0) - { + //if (iteration.Publication.Count > 0) + //{ writer.WriteStartArray("publication"u8); foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Relationship.Count > 0) - { + //if (iteration.Relationship.Count > 0) + //{ writer.WriteStartArray("relationship"u8); foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) @@ -422,11 +426,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.RequirementsSpecification.Count > 0) - { + //if (iteration.RequirementsSpecification.Count > 0) + //{ writer.WriteStartArray("requirementsSpecification"u8); foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) @@ -435,13 +439,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - if (iteration.RuleVerificationList.Count > 0) - { + //if (iteration.RuleVerificationList.Count > 0) + //{ writer.WriteStartArray("ruleVerificationList"u8); foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) @@ -450,11 +454,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.SharedDiagramStyle.Count > 0) - { + //if (iteration.SharedDiagramStyle.Count > 0) + //{ writer.WriteStartArray("sharedDiagramStyle"u8); foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) @@ -463,7 +467,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("sourceIterationIid"u8); @@ -476,8 +480,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.Stakeholder.Count > 0) - { + //if (iteration.Stakeholder.Count > 0) + //{ writer.WriteStartArray("stakeholder"u8); foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) @@ -486,11 +490,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValue.Count > 0) - { + //if (iteration.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -499,11 +503,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValueMap.Count > 0) - { + //if (iteration.StakeholderValueMap.Count > 0) + //{ writer.WriteStartArray("stakeholderValueMap"u8); foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) @@ -512,7 +516,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("topElement"u8); @@ -525,8 +529,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.ValueGroup.Count > 0) - { + //if (iteration.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -535,14 +539,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); - if (iteration.ActualFiniteStateList.Count > 0) - { + //if (iteration.ActualFiniteStateList.Count > 0) + //{ writer.WriteStartArray("actualFiniteStateList"u8); foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -551,7 +555,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -566,8 +570,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.DiagramCanvas.Count > 0) - { + //if (iteration.DiagramCanvas.Count > 0) + //{ writer.WriteStartArray("diagramCanvas"u8); foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) @@ -576,11 +580,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.DomainFileStore.Count > 0) - { + //if (iteration.DomainFileStore.Count > 0) + //{ writer.WriteStartArray("domainFileStore"u8); foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) @@ -589,11 +593,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Element.Count > 0) - { + //if (iteration.Element.Count > 0) + //{ writer.WriteStartArray("element"u8); foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) @@ -602,11 +606,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedDomain.Count > 0) - { + //if (iteration.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -615,11 +619,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedPerson.Count > 0) - { + //if (iteration.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -628,11 +632,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExternalIdentifierMap.Count > 0) - { + //if (iteration.ExternalIdentifierMap.Count > 0) + //{ writer.WriteStartArray("externalIdentifierMap"u8); foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) @@ -641,11 +645,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Goal.Count > 0) - { + //if (iteration.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) @@ -654,7 +658,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -663,8 +667,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (iteration.Option.Count > 0) - { + //if (iteration.Option.Count > 0) + //{ writer.WriteStartArray("option"u8); foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) @@ -673,11 +677,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.PossibleFiniteStateList.Count > 0) - { + //if (iteration.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -686,11 +690,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Publication.Count > 0) - { + //if (iteration.Publication.Count > 0) + //{ writer.WriteStartArray("publication"u8); foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) @@ -699,11 +703,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Relationship.Count > 0) - { + //if (iteration.Relationship.Count > 0) + //{ writer.WriteStartArray("relationship"u8); foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) @@ -712,11 +716,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.RequirementsSpecification.Count > 0) - { + //if (iteration.RequirementsSpecification.Count > 0) + //{ writer.WriteStartArray("requirementsSpecification"u8); foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) @@ -725,13 +729,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - if (iteration.RuleVerificationList.Count > 0) - { + //if (iteration.RuleVerificationList.Count > 0) + //{ writer.WriteStartArray("ruleVerificationList"u8); foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) @@ -740,11 +744,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.SharedDiagramStyle.Count > 0) - { + //if (iteration.SharedDiagramStyle.Count > 0) + //{ writer.WriteStartArray("sharedDiagramStyle"u8); foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) @@ -753,7 +757,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("sourceIterationIid"u8); @@ -766,8 +770,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.Stakeholder.Count > 0) - { + //if (iteration.Stakeholder.Count > 0) + //{ writer.WriteStartArray("stakeholder"u8); foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) @@ -776,11 +780,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValue.Count > 0) - { + //if (iteration.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -789,11 +793,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValueMap.Count > 0) - { + //if (iteration.StakeholderValueMap.Count > 0) + //{ writer.WriteStartArray("stakeholderValueMap"u8); foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) @@ -802,7 +806,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); @@ -817,8 +821,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.ValueGroup.Count > 0) - { + //if (iteration.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -827,7 +831,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -843,8 +847,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.ActualFiniteStateList.Count > 0) - { + //if (iteration.ActualFiniteStateList.Count > 0) + //{ writer.WriteStartArray("actualFiniteStateList"u8); foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -853,7 +857,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); @@ -868,8 +872,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.DiagramCanvas.Count > 0) - { + //if (iteration.DiagramCanvas.Count > 0) + //{ writer.WriteStartArray("diagramCanvas"u8); foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) @@ -878,11 +882,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.DomainFileStore.Count > 0) - { + //if (iteration.DomainFileStore.Count > 0) + //{ writer.WriteStartArray("domainFileStore"u8); foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) @@ -891,11 +895,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Element.Count > 0) - { + //if (iteration.Element.Count > 0) + //{ writer.WriteStartArray("element"u8); foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) @@ -904,11 +908,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedDomain.Count > 0) - { + //if (iteration.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -917,11 +921,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExcludedPerson.Count > 0) - { + //if (iteration.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -930,11 +934,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.ExternalIdentifierMap.Count > 0) - { + //if (iteration.ExternalIdentifierMap.Count > 0) + //{ writer.WriteStartArray("externalIdentifierMap"u8); foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) @@ -943,11 +947,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Goal.Count > 0) - { + //if (iteration.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) @@ -956,7 +960,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -965,8 +969,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (iteration.Option.Count > 0) - { + //if (iteration.Option.Count > 0) + //{ writer.WriteStartArray("option"u8); foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) @@ -975,11 +979,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.PossibleFiniteStateList.Count > 0) - { + //if (iteration.PossibleFiniteStateList.Count > 0) + //{ writer.WriteStartArray("possibleFiniteStateList"u8); foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) @@ -988,11 +992,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Publication.Count > 0) - { + //if (iteration.Publication.Count > 0) + //{ writer.WriteStartArray("publication"u8); foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) @@ -1001,11 +1005,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.Relationship.Count > 0) - { + //if (iteration.Relationship.Count > 0) + //{ writer.WriteStartArray("relationship"u8); foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) @@ -1014,11 +1018,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.RequirementsSpecification.Count > 0) - { + //if (iteration.RequirementsSpecification.Count > 0) + //{ writer.WriteStartArray("requirementsSpecification"u8); foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) @@ -1027,13 +1031,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); - if (iteration.RuleVerificationList.Count > 0) - { + //if (iteration.RuleVerificationList.Count > 0) + //{ writer.WriteStartArray("ruleVerificationList"u8); foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) @@ -1042,11 +1046,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.SharedDiagramStyle.Count > 0) - { + //if (iteration.SharedDiagramStyle.Count > 0) + //{ writer.WriteStartArray("sharedDiagramStyle"u8); foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) @@ -1055,7 +1059,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("sourceIterationIid"u8); @@ -1068,8 +1072,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.Stakeholder.Count > 0) - { + //if (iteration.Stakeholder.Count > 0) + //{ writer.WriteStartArray("stakeholder"u8); foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) @@ -1078,11 +1082,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValue.Count > 0) - { + //if (iteration.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -1091,11 +1095,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iteration.StakeholderValueMap.Count > 0) - { + //if (iteration.StakeholderValueMap.Count > 0) + //{ writer.WriteStartArray("stakeholderValueMap"u8); foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) @@ -1104,7 +1108,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); @@ -1119,8 +1123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (iteration.ValueGroup.Count > 0) - { + //if (iteration.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -1129,7 +1133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -1177,6 +1181,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListActualFiniteStateList && objectListActualFiniteStateList.Any()) { writer.WriteStartArray("actualFiniteStateList"u8); @@ -1230,6 +1239,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiagramCanvas && objectListDiagramCanvas.Any()) { writer.WriteStartArray("diagramCanvas"u8); @@ -1247,6 +1261,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomainFileStore && objectListDomainFileStore.Any()) { writer.WriteStartArray("domainFileStore"u8); @@ -1264,6 +1283,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListElement && objectListElement.Any()) { writer.WriteStartArray("element"u8); @@ -1281,6 +1305,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -1298,6 +1327,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1315,6 +1349,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExternalIdentifierMap && objectListExternalIdentifierMap.Any()) { writer.WriteStartArray("externalIdentifierMap"u8); @@ -1332,6 +1371,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGoal && objectListGoal.Any()) { writer.WriteStartArray("goal"u8); @@ -1403,6 +1447,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListOption && objectListOption.Any()) { writer.WriteStartArray("option"u8); @@ -1420,6 +1469,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) { writer.WriteStartArray("possibleFiniteStateList"u8); @@ -1437,6 +1491,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPublication && objectListPublication.Any()) { writer.WriteStartArray("publication"u8); @@ -1454,6 +1513,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelationship && objectListRelationship.Any()) { writer.WriteStartArray("relationship"u8); @@ -1471,6 +1535,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRequirementsSpecification && objectListRequirementsSpecification.Any()) { writer.WriteStartArray("requirementsSpecification"u8); @@ -1506,6 +1575,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRuleVerificationList && objectListRuleVerificationList.Any()) { writer.WriteStartArray("ruleVerificationList"u8); @@ -1523,6 +1597,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSharedDiagramStyle && objectListSharedDiagramStyle.Any()) { writer.WriteStartArray("sharedDiagramStyle"u8); @@ -1558,6 +1637,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListStakeholder && objectListStakeholder.Any()) { writer.WriteStartArray("stakeholder"u8); @@ -1575,6 +1659,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { writer.WriteStartArray("stakeholderValue"u8); @@ -1592,6 +1681,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListStakeholderValueMap && objectListStakeholderValueMap.Any()) { writer.WriteStartArray("stakeholderValueMap"u8); @@ -1645,6 +1739,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) { writer.WriteStartArray("valueGroup"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index d8b482f28..b3666c02a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -125,8 +129,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - if (iterationSetup.ExcludedDomain.Count > 0) - { + //if (iterationSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -135,11 +139,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iterationSetup.ExcludedPerson.Count > 0) - { + //if (iterationSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -148,7 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("frozenOn"u8); @@ -194,8 +198,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - if (iterationSetup.ExcludedDomain.Count > 0) - { + //if (iterationSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -204,11 +208,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iterationSetup.ExcludedPerson.Count > 0) - { + //if (iterationSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -217,7 +221,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("frozenOn"u8); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); - if (iterationSetup.ExcludedDomain.Count > 0) - { + //if (iterationSetup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -286,11 +290,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (iterationSetup.ExcludedPerson.Count > 0) - { + //if (iterationSetup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -299,7 +303,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("frozenOn"u8); @@ -437,6 +441,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -454,6 +463,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 5321fc899..5a131068e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); - if (linearConversionUnit.Alias.Count > 0) - { + //if (linearConversionUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - if (linearConversionUnit.Definition.Count > 0) - { + //if (linearConversionUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.HyperLink.Count > 0) - { + //if (linearConversionUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -136,8 +140,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); - if (linearConversionUnit.Alias.Count > 0) - { + //if (linearConversionUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -146,15 +150,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - if (linearConversionUnit.Definition.Count > 0) - { + //if (linearConversionUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -163,11 +167,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedDomain.Count > 0) - { + //if (linearConversionUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedPerson.Count > 0) - { + //if (linearConversionUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -189,11 +193,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.HyperLink.Count > 0) - { + //if (linearConversionUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -222,8 +226,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); - if (linearConversionUnit.Alias.Count > 0) - { + //if (linearConversionUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -232,15 +236,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - if (linearConversionUnit.Definition.Count > 0) - { + //if (linearConversionUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -249,11 +253,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedDomain.Count > 0) - { + //if (linearConversionUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -262,11 +266,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedPerson.Count > 0) - { + //if (linearConversionUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -275,11 +279,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.HyperLink.Count > 0) - { + //if (linearConversionUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -288,7 +292,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -320,8 +324,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (linearConversionUnit.Alias.Count > 0) - { + //if (linearConversionUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -330,15 +334,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); - if (linearConversionUnit.Definition.Count > 0) - { + //if (linearConversionUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -347,11 +351,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedDomain.Count > 0) - { + //if (linearConversionUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -360,11 +364,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.ExcludedPerson.Count > 0) - { + //if (linearConversionUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -373,11 +377,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (linearConversionUnit.HyperLink.Count > 0) - { + //if (linearConversionUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -386,7 +390,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -450,6 +454,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -503,6 +512,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -520,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -537,6 +556,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -554,6 +578,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index 60bad268c..2cbd22482 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) - { + //if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) + //{ writer.WriteStartArray("affectedReferenceIid"u8); foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) @@ -90,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -99,8 +103,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - if (logEntryChangelogItem.ExcludedDomain.Count > 0) - { + //if (logEntryChangelogItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logEntryChangelogItem.ExcludedPerson.Count > 0) - { + //if (logEntryChangelogItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -149,8 +153,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); - if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) - { + //if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) + //{ writer.WriteStartArray("affectedReferenceIid"u8); foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) @@ -159,7 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); - if (logEntryChangelogItem.ExcludedDomain.Count > 0) - { + //if (logEntryChangelogItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -178,11 +182,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logEntryChangelogItem.ExcludedPerson.Count > 0) - { + //if (logEntryChangelogItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -191,7 +195,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -265,6 +269,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAffectedReferenceIid && objectListAffectedReferenceIid.Any()) { writer.WriteStartArray("affectedReferenceIid"u8); @@ -336,6 +345,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -353,6 +367,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index d3322fe65..e30c06dfb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); - if (logarithmicScale.Alias.Count > 0) - { + //if (logarithmicScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - if (logarithmicScale.Definition.Count > 0) - { + //if (logarithmicScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,15 +107,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - if (logarithmicScale.HyperLink.Count > 0) - { + //if (logarithmicScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -133,8 +137,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - if (logarithmicScale.MappingToReferenceScale.Count > 0) - { + //if (logarithmicScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -143,7 +147,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -160,8 +164,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - if (logarithmicScale.ReferenceQuantityValue.Count > 0) - { + //if (logarithmicScale.ReferenceQuantityValue.Count > 0) + //{ writer.WriteStartArray("referenceQuantityValue"u8); foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) @@ -170,7 +174,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -179,8 +183,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - if (logarithmicScale.ValueDefinition.Count > 0) - { + //if (logarithmicScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -189,14 +193,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); - if (logarithmicScale.Alias.Count > 0) - { + //if (logarithmicScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -205,13 +209,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - if (logarithmicScale.Definition.Count > 0) - { + //if (logarithmicScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -220,11 +224,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedDomain.Count > 0) - { + //if (logarithmicScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -233,11 +237,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedPerson.Count > 0) - { + //if (logarithmicScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -246,15 +250,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - if (logarithmicScale.HyperLink.Count > 0) - { + //if (logarithmicScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -263,7 +267,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - if (logarithmicScale.MappingToReferenceScale.Count > 0) - { + //if (logarithmicScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -286,7 +290,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -305,8 +309,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - if (logarithmicScale.ReferenceQuantityValue.Count > 0) - { + //if (logarithmicScale.ReferenceQuantityValue.Count > 0) + //{ writer.WriteStartArray("referenceQuantityValue"u8); foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) @@ -315,7 +319,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -324,8 +328,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - if (logarithmicScale.ValueDefinition.Count > 0) - { + //if (logarithmicScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -334,14 +338,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); - if (logarithmicScale.Alias.Count > 0) - { + //if (logarithmicScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -350,13 +354,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - if (logarithmicScale.Definition.Count > 0) - { + //if (logarithmicScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -365,11 +369,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedDomain.Count > 0) - { + //if (logarithmicScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -378,11 +382,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedPerson.Count > 0) - { + //if (logarithmicScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -391,15 +395,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - if (logarithmicScale.HyperLink.Count > 0) - { + //if (logarithmicScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -408,7 +412,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -421,8 +425,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - if (logarithmicScale.MappingToReferenceScale.Count > 0) - { + //if (logarithmicScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -431,7 +435,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -450,8 +454,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - if (logarithmicScale.ReferenceQuantityValue.Count > 0) - { + //if (logarithmicScale.ReferenceQuantityValue.Count > 0) + //{ writer.WriteStartArray("referenceQuantityValue"u8); foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) @@ -460,7 +464,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -471,8 +475,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - if (logarithmicScale.ValueDefinition.Count > 0) - { + //if (logarithmicScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -481,7 +485,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -497,8 +501,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (logarithmicScale.Alias.Count > 0) - { + //if (logarithmicScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -507,13 +511,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); - if (logarithmicScale.Definition.Count > 0) - { + //if (logarithmicScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -522,11 +526,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedDomain.Count > 0) - { + //if (logarithmicScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -535,11 +539,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (logarithmicScale.ExcludedPerson.Count > 0) - { + //if (logarithmicScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -548,15 +552,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); - if (logarithmicScale.HyperLink.Count > 0) - { + //if (logarithmicScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -565,7 +569,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -578,8 +582,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); - if (logarithmicScale.MappingToReferenceScale.Count > 0) - { + //if (logarithmicScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -588,7 +592,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -607,8 +611,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); - if (logarithmicScale.ReferenceQuantityValue.Count > 0) - { + //if (logarithmicScale.ReferenceQuantityValue.Count > 0) + //{ writer.WriteStartArray("referenceQuantityValue"u8); foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) @@ -617,7 +621,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -628,8 +632,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); - if (logarithmicScale.ValueDefinition.Count > 0) - { + //if (logarithmicScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -638,7 +642,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -686,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -721,6 +730,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -738,6 +752,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -755,6 +774,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -808,6 +832,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -915,6 +944,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { writer.WriteStartArray("mappingToReferenceScale"u8); @@ -1076,6 +1110,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListReferenceQuantityValue && objectListReferenceQuantityValue.Any()) { writer.WriteStartArray("referenceQuantityValue"u8); @@ -1165,6 +1204,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index cab5d52c2..b37cb3c78 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -95,8 +99,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - if (mappingToReferenceScale.ExcludedDomain.Count > 0) - { + //if (mappingToReferenceScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (mappingToReferenceScale.ExcludedPerson.Count > 0) - { + //if (mappingToReferenceScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -136,8 +140,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - if (mappingToReferenceScale.ExcludedDomain.Count > 0) - { + //if (mappingToReferenceScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -146,11 +150,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (mappingToReferenceScale.ExcludedPerson.Count > 0) - { + //if (mappingToReferenceScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -159,7 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -190,8 +194,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); - if (mappingToReferenceScale.ExcludedDomain.Count > 0) - { + //if (mappingToReferenceScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -200,11 +204,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (mappingToReferenceScale.ExcludedPerson.Count > 0) - { + //if (mappingToReferenceScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -213,7 +217,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -307,6 +311,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -324,6 +333,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index fc36aa12d..cfa0532fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); - if (modelLogEntry.AffectedDomainIid.Count > 0) - { + //if (modelLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.AffectedItemIid.Count > 0) - { + //if (modelLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) @@ -101,7 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelLogEntry.Category.Count > 0) - { + //if (modelLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -124,7 +128,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -144,8 +148,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); - if (modelLogEntry.AffectedDomainIid.Count > 0) - { + //if (modelLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) @@ -154,11 +158,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.AffectedItemIid.Count > 0) - { + //if (modelLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) @@ -167,7 +171,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -180,8 +184,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelLogEntry.Category.Count > 0) - { + //if (modelLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -190,7 +194,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -199,8 +203,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (modelLogEntry.ExcludedDomain.Count > 0) - { + //if (modelLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.ExcludedPerson.Count > 0) - { + //if (modelLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -238,8 +242,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); - if (modelLogEntry.AffectedDomainIid.Count > 0) - { + //if (modelLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.AffectedItemIid.Count > 0) - { + //if (modelLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -274,8 +278,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelLogEntry.Category.Count > 0) - { + //if (modelLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -293,8 +297,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (modelLogEntry.ExcludedDomain.Count > 0) - { + //if (modelLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -303,11 +307,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.ExcludedPerson.Count > 0) - { + //if (modelLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -316,7 +320,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -325,8 +329,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); - if (modelLogEntry.LogEntryChangelogItem.Count > 0) - { + //if (modelLogEntry.LogEntryChangelogItem.Count > 0) + //{ writer.WriteStartArray("logEntryChangelogItem"u8); foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) @@ -335,7 +339,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -357,8 +361,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelLogEntry.AffectedDomainIid.Count > 0) - { + //if (modelLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) @@ -367,11 +371,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.AffectedItemIid.Count > 0) - { + //if (modelLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) @@ -380,7 +384,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -393,8 +397,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelLogEntry.Category.Count > 0) - { + //if (modelLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -403,7 +407,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -412,8 +416,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (modelLogEntry.ExcludedDomain.Count > 0) - { + //if (modelLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -422,11 +426,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelLogEntry.ExcludedPerson.Count > 0) - { + //if (modelLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -435,7 +439,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -444,8 +448,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); - if (modelLogEntry.LogEntryChangelogItem.Count > 0) - { + //if (modelLogEntry.LogEntryChangelogItem.Count > 0) + //{ writer.WriteStartArray("logEntryChangelogItem"u8); foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) @@ -454,7 +458,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -508,6 +512,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) { writer.WriteStartArray("affectedDomainIid"u8); @@ -525,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) { writer.WriteStartArray("affectedItemIid"u8); @@ -560,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -631,6 +650,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -648,6 +672,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -719,6 +748,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) { writer.WriteStartArray("logEntryChangelogItem"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index da237cf29..0117f8784 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); - if (modelReferenceDataLibrary.Alias.Count > 0) - { + //if (modelReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -101,11 +105,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (modelReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -114,13 +118,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - if (modelReferenceDataLibrary.Constant.Count > 0) - { + //if (modelReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Definition.Count > 0) - { + //if (modelReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.FileType.Count > 0) - { + //if (modelReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Glossary.Count > 0) - { + //if (modelReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.HyperLink.Count > 0) - { + //if (modelReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -194,15 +198,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - if (modelReferenceDataLibrary.ParameterType.Count > 0) - { + //if (modelReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - if (modelReferenceDataLibrary.Rule.Count > 0) - { + //if (modelReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -250,11 +254,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Scale.Count > 0) - { + //if (modelReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -263,13 +267,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - if (modelReferenceDataLibrary.Unit.Count > 0) - { + //if (modelReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -291,14 +295,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); - if (modelReferenceDataLibrary.Alias.Count > 0) - { + //if (modelReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -307,11 +311,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -320,11 +324,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (modelReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -333,13 +337,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - if (modelReferenceDataLibrary.Constant.Count > 0) - { + //if (modelReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -348,11 +352,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -361,11 +365,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Definition.Count > 0) - { + //if (modelReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -374,11 +378,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -387,11 +391,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -400,11 +404,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.FileType.Count > 0) - { + //if (modelReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -413,11 +417,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Glossary.Count > 0) - { + //if (modelReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -426,11 +430,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.HyperLink.Count > 0) - { + //if (modelReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -439,7 +443,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -448,8 +452,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - if (modelReferenceDataLibrary.ParameterType.Count > 0) - { + //if (modelReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -458,11 +462,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -471,7 +475,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -487,8 +491,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - if (modelReferenceDataLibrary.Rule.Count > 0) - { + //if (modelReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -497,11 +501,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Scale.Count > 0) - { + //if (modelReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -510,13 +514,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - if (modelReferenceDataLibrary.Unit.Count > 0) - { + //if (modelReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -525,11 +529,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -538,14 +542,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); - if (modelReferenceDataLibrary.Alias.Count > 0) - { + //if (modelReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -554,11 +558,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -567,11 +571,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (modelReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -580,13 +584,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - if (modelReferenceDataLibrary.Constant.Count > 0) - { + //if (modelReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -595,11 +599,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -608,11 +612,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Definition.Count > 0) - { + //if (modelReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -621,11 +625,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -634,11 +638,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -647,11 +651,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.FileType.Count > 0) - { + //if (modelReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -660,11 +664,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Glossary.Count > 0) - { + //if (modelReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -673,11 +677,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.HyperLink.Count > 0) - { + //if (modelReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -686,7 +690,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -695,8 +699,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - if (modelReferenceDataLibrary.ParameterType.Count > 0) - { + //if (modelReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -705,11 +709,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -718,7 +722,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -734,8 +738,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - if (modelReferenceDataLibrary.Rule.Count > 0) - { + //if (modelReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -744,11 +748,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Scale.Count > 0) - { + //if (modelReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -757,15 +761,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - if (modelReferenceDataLibrary.Unit.Count > 0) - { + //if (modelReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -774,11 +778,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -787,7 +791,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -803,8 +807,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (modelReferenceDataLibrary.Alias.Count > 0) - { + //if (modelReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -813,11 +817,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -826,11 +830,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (modelReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -839,13 +843,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - if (modelReferenceDataLibrary.Constant.Count > 0) - { + //if (modelReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -854,11 +858,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -867,11 +871,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Definition.Count > 0) - { + //if (modelReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -880,11 +884,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -893,11 +897,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -906,11 +910,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.FileType.Count > 0) - { + //if (modelReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -919,11 +923,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Glossary.Count > 0) - { + //if (modelReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -932,11 +936,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.HyperLink.Count > 0) - { + //if (modelReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -945,7 +949,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -954,8 +958,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); - if (modelReferenceDataLibrary.ParameterType.Count > 0) - { + //if (modelReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -964,11 +968,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -977,7 +981,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -993,8 +997,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - if (modelReferenceDataLibrary.Rule.Count > 0) - { + //if (modelReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -1003,11 +1007,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.Scale.Count > 0) - { + //if (modelReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -1016,15 +1020,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - if (modelReferenceDataLibrary.Unit.Count > 0) - { + //if (modelReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -1033,11 +1037,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -1046,7 +1050,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -1094,6 +1098,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -1111,6 +1120,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) { writer.WriteStartArray("baseQuantityKind"u8); @@ -1128,6 +1142,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) { writer.WriteStartArray("baseUnit"u8); @@ -1163,6 +1182,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListConstant && objectListConstant.Any()) { writer.WriteStartArray("constant"u8); @@ -1180,6 +1204,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) { writer.WriteStartArray("definedCategory"u8); @@ -1197,6 +1226,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -1214,6 +1248,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -1231,6 +1270,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1248,6 +1292,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { writer.WriteStartArray("fileType"u8); @@ -1265,6 +1314,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) { writer.WriteStartArray("glossary"u8); @@ -1282,6 +1336,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -1353,6 +1412,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { writer.WriteStartArray("parameterType"u8); @@ -1370,6 +1434,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) { writer.WriteStartArray("referenceSource"u8); @@ -1423,6 +1492,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRule && objectListRule.Any()) { writer.WriteStartArray("rule"u8); @@ -1440,6 +1514,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListScale && objectListScale.Any()) { writer.WriteStartArray("scale"u8); @@ -1493,6 +1572,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUnit && objectListUnit.Any()) { writer.WriteStartArray("unit"u8); @@ -1510,6 +1594,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) { writer.WriteStartArray("unitPrefix"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 84ba9f986..58ea710d6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - if (modellingThingReference.ExcludedDomain.Count > 0) - { + //if (modellingThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modellingThingReference.ExcludedPerson.Count > 0) - { + //if (modellingThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -121,8 +125,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - if (modellingThingReference.ExcludedDomain.Count > 0) - { + //if (modellingThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -131,11 +135,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modellingThingReference.ExcludedPerson.Count > 0) - { + //if (modellingThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -175,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); - if (modellingThingReference.ExcludedDomain.Count > 0) - { + //if (modellingThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (modellingThingReference.ExcludedPerson.Count > 0) - { + //if (modellingThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -276,6 +280,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -293,6 +302,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index c02a2a1fb..d9095f126 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); - if (multiRelationshipRule.Alias.Count > 0) - { + //if (multiRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - if (multiRelationshipRule.Definition.Count > 0) - { + //if (multiRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.HyperLink.Count > 0) - { + //if (multiRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - if (multiRelationshipRule.RelatedCategory.Count > 0) - { + //if (multiRelationshipRule.RelatedCategory.Count > 0) + //{ writer.WriteStartArray("relatedCategory"u8); foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) @@ -139,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -151,8 +155,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); - if (multiRelationshipRule.Alias.Count > 0) - { + //if (multiRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -161,13 +165,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - if (multiRelationshipRule.Definition.Count > 0) - { + //if (multiRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedDomain.Count > 0) - { + //if (multiRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -189,11 +193,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedPerson.Count > 0) - { + //if (multiRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -202,11 +206,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.HyperLink.Count > 0) - { + //if (multiRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -215,7 +219,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -230,8 +234,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - if (multiRelationshipRule.RelatedCategory.Count > 0) - { + //if (multiRelationshipRule.RelatedCategory.Count > 0) + //{ writer.WriteStartArray("relatedCategory"u8); foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) @@ -240,7 +244,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -252,8 +256,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); - if (multiRelationshipRule.Alias.Count > 0) - { + //if (multiRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -262,13 +266,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - if (multiRelationshipRule.Definition.Count > 0) - { + //if (multiRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -277,11 +281,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedDomain.Count > 0) - { + //if (multiRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -290,11 +294,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedPerson.Count > 0) - { + //if (multiRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -303,11 +307,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.HyperLink.Count > 0) - { + //if (multiRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -316,7 +320,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -331,8 +335,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - if (multiRelationshipRule.RelatedCategory.Count > 0) - { + //if (multiRelationshipRule.RelatedCategory.Count > 0) + //{ writer.WriteStartArray("relatedCategory"u8); foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) @@ -341,7 +345,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -365,8 +369,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (multiRelationshipRule.Alias.Count > 0) - { + //if (multiRelationshipRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -375,13 +379,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); - if (multiRelationshipRule.Definition.Count > 0) - { + //if (multiRelationshipRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -390,11 +394,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedDomain.Count > 0) - { + //if (multiRelationshipRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -403,11 +407,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.ExcludedPerson.Count > 0) - { + //if (multiRelationshipRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -416,11 +420,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationshipRule.HyperLink.Count > 0) - { + //if (multiRelationshipRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -429,7 +433,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -444,8 +448,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); - if (multiRelationshipRule.RelatedCategory.Count > 0) - { + //if (multiRelationshipRule.RelatedCategory.Count > 0) + //{ writer.WriteStartArray("relatedCategory"u8); foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) @@ -454,7 +458,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -510,6 +514,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -545,6 +554,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -562,6 +576,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -579,6 +598,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -596,6 +620,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -721,6 +750,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedCategory && objectListRelatedCategory.Any()) { writer.WriteStartArray("relatedCategory"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 6090ab3ed..79380cf43 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); - if (multiRelationship.Category.Count > 0) - { + //if (multiRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - if (multiRelationship.RelatedThing.Count > 0) - { + //if (multiRelationship.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -107,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -115,8 +119,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); - if (multiRelationship.Category.Count > 0) - { + //if (multiRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -125,13 +129,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - if (multiRelationship.ExcludedDomain.Count > 0) - { + //if (multiRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -140,11 +144,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.ExcludedPerson.Count > 0) - { + //if (multiRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -153,7 +157,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -162,8 +166,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - if (multiRelationship.ParameterValue.Count > 0) - { + //if (multiRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -172,11 +176,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.RelatedThing.Count > 0) - { + //if (multiRelationship.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -185,7 +189,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -193,8 +197,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); - if (multiRelationship.Category.Count > 0) - { + //if (multiRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -203,13 +207,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - if (multiRelationship.ExcludedDomain.Count > 0) - { + //if (multiRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -218,11 +222,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.ExcludedPerson.Count > 0) - { + //if (multiRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -231,7 +235,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -242,8 +246,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - if (multiRelationship.ParameterValue.Count > 0) - { + //if (multiRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.RelatedThing.Count > 0) - { + //if (multiRelationship.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -265,7 +269,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -285,8 +289,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (multiRelationship.Category.Count > 0) - { + //if (multiRelationship.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) @@ -295,13 +299,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); - if (multiRelationship.ExcludedDomain.Count > 0) - { + //if (multiRelationship.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -310,11 +314,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.ExcludedPerson.Count > 0) - { + //if (multiRelationship.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -323,7 +327,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -334,8 +338,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); - if (multiRelationship.ParameterValue.Count > 0) - { + //if (multiRelationship.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -344,11 +348,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (multiRelationship.RelatedThing.Count > 0) - { + //if (multiRelationship.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -357,7 +361,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -409,6 +413,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -444,6 +453,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -461,6 +475,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -550,6 +569,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { writer.WriteStartArray("parameterValue"u8); @@ -567,6 +591,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index 27770f1f8..a2563af1d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -95,8 +99,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - if (naturalLanguage.ExcludedDomain.Count > 0) - { + //if (naturalLanguage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (naturalLanguage.ExcludedPerson.Count > 0) - { + //if (naturalLanguage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - if (naturalLanguage.ExcludedDomain.Count > 0) - { + //if (naturalLanguage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -148,11 +152,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (naturalLanguage.ExcludedPerson.Count > 0) - { + //if (naturalLanguage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -161,7 +165,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -194,8 +198,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); - if (naturalLanguage.ExcludedDomain.Count > 0) - { + //if (naturalLanguage.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -204,11 +208,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (naturalLanguage.ExcludedPerson.Count > 0) - { + //if (naturalLanguage.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -217,7 +221,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -297,6 +301,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -314,6 +323,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index b734ebda2..b95c667cb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - if (nestedElement.ElementUsage.Count > 0) - { + //if (nestedElement.ElementUsage.Count > 0) + //{ writer.WriteStartArray("elementUsage"u8); foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) @@ -90,15 +94,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); writer.WritePropertyName("isVolatile"u8); writer.WriteBooleanValue(nestedElement.IsVolatile); - if (nestedElement.NestedParameter.Count > 0) - { + //if (nestedElement.NestedParameter.Count > 0) + //{ writer.WriteStartArray("nestedParameter"u8); foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) @@ -107,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -119,8 +123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - if (nestedElement.ElementUsage.Count > 0) - { + //if (nestedElement.ElementUsage.Count > 0) + //{ writer.WriteStartArray("elementUsage"u8); foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedDomain.Count > 0) - { + //if (nestedElement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedPerson.Count > 0) - { + //if (nestedElement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -164,8 +168,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (nestedElement.NestedParameter.Count > 0) - { + //if (nestedElement.NestedParameter.Count > 0) + //{ writer.WriteStartArray("nestedParameter"u8); foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) @@ -174,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -186,8 +190,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - if (nestedElement.ElementUsage.Count > 0) - { + //if (nestedElement.ElementUsage.Count > 0) + //{ writer.WriteStartArray("elementUsage"u8); foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedDomain.Count > 0) - { + //if (nestedElement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedPerson.Count > 0) - { + //if (nestedElement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -231,8 +235,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (nestedElement.NestedParameter.Count > 0) - { + //if (nestedElement.NestedParameter.Count > 0) + //{ writer.WriteStartArray("nestedParameter"u8); foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) @@ -241,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); - if (nestedElement.ElementUsage.Count > 0) - { + //if (nestedElement.ElementUsage.Count > 0) + //{ writer.WriteStartArray("elementUsage"u8); foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedDomain.Count > 0) - { + //if (nestedElement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -289,11 +293,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedElement.ExcludedPerson.Count > 0) - { + //if (nestedElement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -302,7 +306,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -311,8 +315,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (nestedElement.NestedParameter.Count > 0) - { + //if (nestedElement.NestedParameter.Count > 0) + //{ writer.WriteStartArray("nestedParameter"u8); foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -393,6 +397,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListElementUsage && objectListElementUsage.Any()) { writer.WriteStartArray("elementUsage"u8); @@ -410,6 +419,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -427,6 +441,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -498,6 +517,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListNestedParameter && objectListNestedParameter.Any()) { writer.WriteStartArray("nestedParameter"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index 5445c894a..5feb723db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -125,8 +129,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - if (nestedParameter.ExcludedDomain.Count > 0) - { + //if (nestedParameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -135,11 +139,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedParameter.ExcludedPerson.Count > 0) - { + //if (nestedParameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -148,7 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -183,8 +187,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - if (nestedParameter.ExcludedDomain.Count > 0) - { + //if (nestedParameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -193,11 +197,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedParameter.ExcludedPerson.Count > 0) - { + //if (nestedParameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -206,7 +210,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -254,8 +258,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); - if (nestedParameter.ExcludedDomain.Count > 0) - { + //if (nestedParameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -264,11 +268,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (nestedParameter.ExcludedPerson.Count > 0) - { + //if (nestedParameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -277,7 +281,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -411,6 +415,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -428,6 +437,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 93208c265..898aae7fc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -91,8 +95,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - if (notExpression.ExcludedDomain.Count > 0) - { + //if (notExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -101,11 +105,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (notExpression.ExcludedPerson.Count > 0) - { + //if (notExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -114,7 +118,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -130,8 +134,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - if (notExpression.ExcludedDomain.Count > 0) - { + //if (notExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -140,11 +144,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (notExpression.ExcludedPerson.Count > 0) - { + //if (notExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -153,7 +157,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -182,8 +186,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); - if (notExpression.ExcludedDomain.Count > 0) - { + //if (notExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -192,11 +196,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (notExpression.ExcludedPerson.Count > 0) - { + //if (notExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -205,7 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -281,6 +285,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -298,6 +307,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 752c91ce6..b2967d253 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); - if (option.Alias.Count > 0) - { + //if (option.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.Category.Count > 0) - { + //if (option.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - if (option.Definition.Count > 0) - { + //if (option.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.HyperLink.Count > 0) - { + //if (option.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,15 +133,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - if (option.NestedElement.Count > 0) - { + //if (option.NestedElement.Count > 0) + //{ writer.WriteStartArray("nestedElement"u8); foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) @@ -146,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -156,8 +160,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); - if (option.Alias.Count > 0) - { + //if (option.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.Category.Count > 0) - { + //if (option.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) @@ -179,13 +183,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - if (option.Definition.Count > 0) - { + //if (option.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) @@ -194,11 +198,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedDomain.Count > 0) - { + //if (option.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -207,11 +211,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedPerson.Count > 0) - { + //if (option.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -220,11 +224,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.HyperLink.Count > 0) - { + //if (option.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -233,7 +237,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -242,8 +246,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - if (option.NestedElement.Count > 0) - { + //if (option.NestedElement.Count > 0) + //{ writer.WriteStartArray("nestedElement"u8); foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) @@ -252,7 +256,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -262,8 +266,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); - if (option.Alias.Count > 0) - { + //if (option.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) @@ -272,11 +276,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.Category.Count > 0) - { + //if (option.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) @@ -285,13 +289,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - if (option.Definition.Count > 0) - { + //if (option.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) @@ -300,11 +304,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedDomain.Count > 0) - { + //if (option.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -313,11 +317,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedPerson.Count > 0) - { + //if (option.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -326,11 +330,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.HyperLink.Count > 0) - { + //if (option.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -339,7 +343,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -348,8 +352,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - if (option.NestedElement.Count > 0) - { + //if (option.NestedElement.Count > 0) + //{ writer.WriteStartArray("nestedElement"u8); foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) @@ -358,7 +362,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -380,8 +384,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (option.Alias.Count > 0) - { + //if (option.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) @@ -390,11 +394,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.Category.Count > 0) - { + //if (option.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) @@ -403,13 +407,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); - if (option.Definition.Count > 0) - { + //if (option.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) @@ -418,11 +422,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedDomain.Count > 0) - { + //if (option.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -431,11 +435,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.ExcludedPerson.Count > 0) - { + //if (option.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -444,11 +448,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (option.HyperLink.Count > 0) - { + //if (option.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -457,7 +461,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -466,8 +470,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); - if (option.NestedElement.Count > 0) - { + //if (option.NestedElement.Count > 0) + //{ writer.WriteStartArray("nestedElement"u8); foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) @@ -476,7 +480,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -530,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -547,6 +556,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -582,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -599,6 +618,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -616,6 +640,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -633,6 +662,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -704,6 +738,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListNestedElement && objectListNestedElement.Any()) { writer.WriteStartArray("nestedElement"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index a0f4195cc..69d0c0183 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -84,8 +88,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - if (orExpression.Term.Count > 0) - { + //if (orExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -94,7 +98,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -102,8 +106,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - if (orExpression.ExcludedDomain.Count > 0) - { + //if (orExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -112,11 +116,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (orExpression.ExcludedPerson.Count > 0) - { + //if (orExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -125,7 +129,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - if (orExpression.Term.Count > 0) - { + //if (orExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -152,8 +156,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - if (orExpression.ExcludedDomain.Count > 0) - { + //if (orExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -162,11 +166,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (orExpression.ExcludedPerson.Count > 0) - { + //if (orExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -175,7 +179,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -184,8 +188,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - if (orExpression.Term.Count > 0) - { + //if (orExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); @@ -215,8 +219,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); - if (orExpression.ExcludedDomain.Count > 0) - { + //if (orExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -225,11 +229,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (orExpression.ExcludedPerson.Count > 0) - { + //if (orExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -238,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -247,8 +251,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); - if (orExpression.Term.Count > 0) - { + //if (orExpression.Term.Count > 0) + //{ writer.WriteStartArray("term"u8); foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) @@ -257,7 +261,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); @@ -325,6 +329,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -342,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -413,6 +427,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListTerm && objectListTerm.Any()) { writer.WriteStartArray("term"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index ea5721c2a..0fa8b6e72 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); - if (ordinalScale.Alias.Count > 0) - { + //if (ordinalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - if (ordinalScale.Definition.Count > 0) - { + //if (ordinalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.HyperLink.Count > 0) - { + //if (ordinalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - if (ordinalScale.MappingToReferenceScale.Count > 0) - { + //if (ordinalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -160,8 +164,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - if (ordinalScale.ValueDefinition.Count > 0) - { + //if (ordinalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -170,14 +174,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); - if (ordinalScale.Alias.Count > 0) - { + //if (ordinalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -186,13 +190,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - if (ordinalScale.Definition.Count > 0) - { + //if (ordinalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -201,11 +205,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedDomain.Count > 0) - { + //if (ordinalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -214,11 +218,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedPerson.Count > 0) - { + //if (ordinalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -227,11 +231,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.HyperLink.Count > 0) - { + //if (ordinalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -240,7 +244,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -251,8 +255,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - if (ordinalScale.MappingToReferenceScale.Count > 0) - { + //if (ordinalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -286,8 +290,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - if (ordinalScale.ValueDefinition.Count > 0) - { + //if (ordinalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -296,14 +300,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); - if (ordinalScale.Alias.Count > 0) - { + //if (ordinalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -312,13 +316,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - if (ordinalScale.Definition.Count > 0) - { + //if (ordinalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedDomain.Count > 0) - { + //if (ordinalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedPerson.Count > 0) - { + //if (ordinalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.HyperLink.Count > 0) - { + //if (ordinalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -366,7 +370,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -377,8 +381,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - if (ordinalScale.MappingToReferenceScale.Count > 0) - { + //if (ordinalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -387,7 +391,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -414,8 +418,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - if (ordinalScale.ValueDefinition.Count > 0) - { + //if (ordinalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -424,7 +428,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -440,8 +444,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (ordinalScale.Alias.Count > 0) - { + //if (ordinalScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -450,13 +454,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); - if (ordinalScale.Definition.Count > 0) - { + //if (ordinalScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -465,11 +469,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedDomain.Count > 0) - { + //if (ordinalScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -478,11 +482,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.ExcludedPerson.Count > 0) - { + //if (ordinalScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -491,11 +495,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ordinalScale.HyperLink.Count > 0) - { + //if (ordinalScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -504,7 +508,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -515,8 +519,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); - if (ordinalScale.MappingToReferenceScale.Count > 0) - { + //if (ordinalScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -525,7 +529,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -552,8 +556,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); - if (ordinalScale.ValueDefinition.Count > 0) - { + //if (ordinalScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -562,7 +566,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -610,6 +614,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -645,6 +654,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -662,6 +676,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -679,6 +698,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -696,6 +720,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -785,6 +814,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { writer.WriteStartArray("mappingToReferenceScale"u8); @@ -1018,6 +1052,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 1884c3192..177b9768e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -95,8 +99,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - if (organization.ExcludedDomain.Count > 0) - { + //if (organization.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (organization.ExcludedPerson.Count > 0) - { + //if (organization.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - if (organization.ExcludedDomain.Count > 0) - { + //if (organization.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -148,11 +152,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (organization.ExcludedPerson.Count > 0) - { + //if (organization.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -161,7 +165,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -194,8 +198,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); - if (organization.ExcludedDomain.Count > 0) - { + //if (organization.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -204,11 +208,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (organization.ExcludedPerson.Count > 0) - { + //if (organization.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -217,7 +221,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -297,6 +301,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -314,6 +323,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 84c47dfbd..697f0bd5f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - if (organizationalParticipant.ExcludedDomain.Count > 0) - { + //if (organizationalParticipant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (organizationalParticipant.ExcludedPerson.Count > 0) - { + //if (organizationalParticipant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -132,8 +136,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); - if (organizationalParticipant.ExcludedDomain.Count > 0) - { + //if (organizationalParticipant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (organizationalParticipant.ExcludedPerson.Count > 0) - { + //if (organizationalParticipant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -231,6 +235,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -248,6 +257,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 5f714d67f..070d8d83b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - if (ownedStyle.ExcludedDomain.Count > 0) - { + //if (ownedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ownedStyle.ExcludedPerson.Count > 0) - { + //if (ownedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -236,8 +240,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (ownedStyle.UsedColor.Count > 0) - { + //if (ownedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -246,7 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -254,8 +258,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - if (ownedStyle.ExcludedDomain.Count > 0) - { + //if (ownedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -264,11 +268,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ownedStyle.ExcludedPerson.Count > 0) - { + //if (ownedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -277,7 +281,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -413,8 +417,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); - if (ownedStyle.UsedColor.Count > 0) - { + //if (ownedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -423,7 +427,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -442,8 +446,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); - if (ownedStyle.ExcludedDomain.Count > 0) - { + //if (ownedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -452,11 +456,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ownedStyle.ExcludedPerson.Count > 0) - { + //if (ownedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -465,7 +469,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -601,8 +605,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); - if (ownedStyle.UsedColor.Count > 0) - { + //if (ownedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -611,7 +615,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -677,6 +681,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -694,6 +703,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1017,6 +1031,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) { writer.WriteStartArray("usedColor"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index 974d66cea..71c3cb0f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); - if (page.Category.Count > 0) - { + //if (page.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (page.ExcludedDomain.Count > 0) - { + //if (page.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (page.ExcludedPerson.Count > 0) - { + //if (page.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - if (page.Note.Count > 0) - { + //if (page.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -149,8 +153,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); - if (page.Category.Count > 0) - { + //if (page.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) @@ -159,15 +163,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (page.ExcludedDomain.Count > 0) - { + //if (page.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (page.ExcludedPerson.Count > 0) - { + //if (page.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -189,7 +193,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -198,8 +202,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - if (page.Note.Count > 0) - { + //if (page.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -208,7 +212,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -232,8 +236,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (page.Category.Count > 0) - { + //if (page.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) @@ -242,15 +246,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (page.ExcludedDomain.Count > 0) - { + //if (page.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -259,11 +263,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (page.ExcludedPerson.Count > 0) - { + //if (page.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -272,7 +276,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -281,8 +285,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); - if (page.Note.Count > 0) - { + //if (page.Note.Count > 0) + //{ writer.WriteStartArray("note"u8); foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) @@ -291,7 +295,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -347,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -400,6 +409,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -417,6 +431,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -488,6 +507,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListNote && objectListNote.Any()) { writer.WriteStartArray("note"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index f23c6492a..dcc2931db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -112,8 +116,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameterGroup.ExcludedDomain.Count > 0) - { + //if (parameterGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -122,11 +126,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterGroup.ExcludedPerson.Count > 0) - { + //if (parameterGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -135,7 +139,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -161,8 +165,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameterGroup.ExcludedDomain.Count > 0) - { + //if (parameterGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -171,11 +175,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterGroup.ExcludedPerson.Count > 0) - { + //if (parameterGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -184,7 +188,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -223,8 +227,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameterGroup.ExcludedDomain.Count > 0) - { + //if (parameterGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -233,11 +237,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterGroup.ExcludedPerson.Count > 0) - { + //if (parameterGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -246,7 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -340,6 +344,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -357,6 +366,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 8a7b799b1..68aaad386 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - if (parameterOverride.ParameterSubscription.Count > 0) - { + //if (parameterOverride.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -96,13 +100,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); - if (parameterOverride.ValueSet.Count > 0) - { + //if (parameterOverride.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -111,7 +115,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -119,8 +123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - if (parameterOverride.ExcludedDomain.Count > 0) - { + //if (parameterOverride.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverride.ExcludedPerson.Count > 0) - { + //if (parameterOverride.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,7 +146,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -153,8 +157,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - if (parameterOverride.ParameterSubscription.Count > 0) - { + //if (parameterOverride.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -163,13 +167,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); - if (parameterOverride.ValueSet.Count > 0) - { + //if (parameterOverride.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -178,7 +182,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -186,8 +190,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - if (parameterOverride.ExcludedDomain.Count > 0) - { + //if (parameterOverride.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverride.ExcludedPerson.Count > 0) - { + //if (parameterOverride.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -220,8 +224,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - if (parameterOverride.ParameterSubscription.Count > 0) - { + //if (parameterOverride.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -230,15 +234,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); - if (parameterOverride.ValueSet.Count > 0) - { + //if (parameterOverride.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); - if (parameterOverride.ExcludedDomain.Count > 0) - { + //if (parameterOverride.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverride.ExcludedPerson.Count > 0) - { + //if (parameterOverride.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -289,7 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -300,8 +304,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); - if (parameterOverride.ParameterSubscription.Count > 0) - { + //if (parameterOverride.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -310,15 +314,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); - if (parameterOverride.ValueSet.Count > 0) - { + //if (parameterOverride.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -327,7 +331,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -393,6 +397,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -410,6 +419,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -499,6 +513,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) { writer.WriteStartArray("parameterSubscription"u8); @@ -552,6 +571,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { writer.WriteStartArray("valueSet"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 778785534..425d31e71 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -99,8 +103,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -168,7 +172,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -204,8 +208,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); - if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -214,11 +218,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - { + //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -227,7 +231,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -317,6 +321,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -334,6 +343,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index fc9ef482a..212b3b2a5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -101,8 +105,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - if (parameter.ParameterSubscription.Count > 0) - { + //if (parameter.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -111,7 +115,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -150,8 +154,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameter.ValueSet.Count > 0) - { + //if (parameter.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -160,7 +164,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -170,8 +174,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - if (parameter.ExcludedDomain.Count > 0) - { + //if (parameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -180,11 +184,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameter.ExcludedPerson.Count > 0) - { + //if (parameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -193,7 +197,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -217,8 +221,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - if (parameter.ParameterSubscription.Count > 0) - { + //if (parameter.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -227,7 +231,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameter.ValueSet.Count > 0) - { + //if (parameter.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -276,7 +280,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -286,8 +290,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - if (parameter.ExcludedDomain.Count > 0) - { + //if (parameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -296,11 +300,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameter.ExcludedPerson.Count > 0) - { + //if (parameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -309,7 +313,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -333,8 +337,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - if (parameter.ParameterSubscription.Count > 0) - { + //if (parameter.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -343,7 +347,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -385,8 +389,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); - if (parameter.ValueSet.Count > 0) - { + //if (parameter.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -395,7 +399,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -416,8 +420,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); - if (parameter.ExcludedDomain.Count > 0) - { + //if (parameter.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -426,11 +430,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameter.ExcludedPerson.Count > 0) - { + //if (parameter.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -439,7 +443,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); @@ -463,8 +467,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); - if (parameter.ParameterSubscription.Count > 0) - { + //if (parameter.ParameterSubscription.Count > 0) + //{ writer.WriteStartArray("parameterSubscription"u8); foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) @@ -473,7 +477,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); @@ -515,8 +519,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); - if (parameter.ValueSet.Count > 0) - { + //if (parameter.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -525,7 +529,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -609,6 +613,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -626,6 +635,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -751,6 +765,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) { writer.WriteStartArray("parameterSubscription"u8); @@ -876,6 +895,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { writer.WriteStartArray("valueSet"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 5ba2383a8..440b30b32 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); - if (parameterSubscription.ValueSet.Count > 0) - { + //if (parameterSubscription.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -96,7 +100,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -104,8 +108,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - if (parameterSubscription.ExcludedDomain.Count > 0) - { + //if (parameterSubscription.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -114,11 +118,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscription.ExcludedPerson.Count > 0) - { + //if (parameterSubscription.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -127,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); - if (parameterSubscription.ValueSet.Count > 0) - { + //if (parameterSubscription.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -148,7 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -156,8 +160,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - if (parameterSubscription.ExcludedDomain.Count > 0) - { + //if (parameterSubscription.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscription.ExcludedPerson.Count > 0) - { + //if (parameterSubscription.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -179,7 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -192,8 +196,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); - if (parameterSubscription.ValueSet.Count > 0) - { + //if (parameterSubscription.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -221,8 +225,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); - if (parameterSubscription.ExcludedDomain.Count > 0) - { + //if (parameterSubscription.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscription.ExcludedPerson.Count > 0) - { + //if (parameterSubscription.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,7 +248,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -257,8 +261,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); - if (parameterSubscription.ValueSet.Count > 0) - { + //if (parameterSubscription.ValueSet.Count > 0) + //{ writer.WriteStartArray("valueSet"u8); foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) @@ -267,7 +271,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -333,6 +337,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -350,6 +359,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -457,6 +471,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) { writer.WriteStartArray("valueSet"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 940b861be..0d52bc2f0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -94,8 +98,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -104,11 +108,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -117,7 +121,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -136,8 +140,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -146,11 +150,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -159,7 +163,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -191,8 +195,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); - if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -201,11 +205,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - { + //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -214,7 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -293,6 +297,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -310,6 +319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index c114fa1dd..0d2bc1743 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -104,8 +108,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - if (parameterTypeComponent.ExcludedDomain.Count > 0) - { + //if (parameterTypeComponent.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -114,11 +118,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterTypeComponent.ExcludedPerson.Count > 0) - { + //if (parameterTypeComponent.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -127,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -156,8 +160,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - if (parameterTypeComponent.ExcludedDomain.Count > 0) - { + //if (parameterTypeComponent.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterTypeComponent.ExcludedPerson.Count > 0) - { + //if (parameterTypeComponent.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -179,7 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -221,8 +225,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); - if (parameterTypeComponent.ExcludedDomain.Count > 0) - { + //if (parameterTypeComponent.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterTypeComponent.ExcludedPerson.Count > 0) - { + //if (parameterTypeComponent.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,7 +248,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -333,6 +337,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -350,6 +359,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 5503bc178..1a48750f0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -141,8 +145,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - if (parameterValueSet.ExcludedDomain.Count > 0) - { + //if (parameterValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -151,11 +155,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterValueSet.ExcludedPerson.Count > 0) - { + //if (parameterValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -164,7 +168,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -207,8 +211,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - if (parameterValueSet.ExcludedDomain.Count > 0) - { + //if (parameterValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterValueSet.ExcludedPerson.Count > 0) - { + //if (parameterValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -230,7 +234,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -286,8 +290,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); - if (parameterValueSet.ExcludedDomain.Count > 0) - { + //if (parameterValueSet.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -296,11 +300,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterValueSet.ExcludedPerson.Count > 0) - { + //if (parameterValueSet.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -309,7 +313,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -433,6 +437,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -450,6 +459,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index 076301508..c46de9c74 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); - if (parameterizedCategoryRule.Alias.Count > 0) - { + //if (parameterizedCategoryRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - if (parameterizedCategoryRule.Definition.Count > 0) - { + //if (parameterizedCategoryRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.HyperLink.Count > 0) - { + //if (parameterizedCategoryRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - if (parameterizedCategoryRule.ParameterType.Count > 0) - { + //if (parameterizedCategoryRule.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); - if (parameterizedCategoryRule.Alias.Count > 0) - { + //if (parameterizedCategoryRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,15 +161,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - if (parameterizedCategoryRule.Definition.Count > 0) - { + //if (parameterizedCategoryRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -174,11 +178,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -187,11 +191,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -200,11 +204,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.HyperLink.Count > 0) - { + //if (parameterizedCategoryRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -213,7 +217,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - if (parameterizedCategoryRule.ParameterType.Count > 0) - { + //if (parameterizedCategoryRule.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -234,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); - if (parameterizedCategoryRule.Alias.Count > 0) - { + //if (parameterizedCategoryRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,15 +258,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - if (parameterizedCategoryRule.Definition.Count > 0) - { + //if (parameterizedCategoryRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -284,11 +288,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -297,11 +301,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.HyperLink.Count > 0) - { + //if (parameterizedCategoryRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -310,7 +314,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -321,8 +325,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - if (parameterizedCategoryRule.ParameterType.Count > 0) - { + //if (parameterizedCategoryRule.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -331,7 +335,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (parameterizedCategoryRule.Alias.Count > 0) - { + //if (parameterizedCategoryRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,15 +367,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); - if (parameterizedCategoryRule.Definition.Count > 0) - { + //if (parameterizedCategoryRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -380,11 +384,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -393,11 +397,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - { + //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -406,11 +410,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parameterizedCategoryRule.HyperLink.Count > 0) - { + //if (parameterizedCategoryRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -419,7 +423,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -430,8 +434,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); - if (parameterizedCategoryRule.ParameterType.Count > 0) - { + //if (parameterizedCategoryRule.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -440,7 +444,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -547,6 +556,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -564,6 +578,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -581,6 +600,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -598,6 +622,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -687,6 +716,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { writer.WriteStartArray("parameterType"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 0efb4f32e..04d2ce36a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - if (parametricConstraint.Expression.Count > 0) - { + //if (parametricConstraint.Expression.Count > 0) + //{ writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -90,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -113,8 +117,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - if (parametricConstraint.ExcludedDomain.Count > 0) - { + //if (parametricConstraint.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -123,11 +127,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.ExcludedPerson.Count > 0) - { + //if (parametricConstraint.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -136,11 +140,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.Expression.Count > 0) - { + //if (parametricConstraint.Expression.Count > 0) + //{ writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -149,7 +153,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -174,8 +178,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - if (parametricConstraint.ExcludedDomain.Count > 0) - { + //if (parametricConstraint.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -184,11 +188,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.ExcludedPerson.Count > 0) - { + //if (parametricConstraint.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -197,11 +201,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.Expression.Count > 0) - { + //if (parametricConstraint.Expression.Count > 0) + //{ writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -210,7 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -248,8 +252,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); - if (parametricConstraint.ExcludedDomain.Count > 0) - { + //if (parametricConstraint.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -258,11 +262,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.ExcludedPerson.Count > 0) - { + //if (parametricConstraint.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (parametricConstraint.Expression.Count > 0) - { + //if (parametricConstraint.Expression.Count > 0) + //{ writer.WriteStartArray("expression"u8); foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -369,6 +373,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -386,6 +395,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -403,6 +417,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExpression && objectListExpression.Any()) { writer.WriteStartArray("expression"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index fc16aaadb..c9e11a2a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - if (participantPermission.ExcludedDomain.Count > 0) - { + //if (participantPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantPermission.ExcludedPerson.Count > 0) - { + //if (participantPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - if (participantPermission.ExcludedDomain.Count > 0) - { + //if (participantPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -150,11 +154,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantPermission.ExcludedPerson.Count > 0) - { + //if (participantPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -163,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -196,8 +200,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); - if (participantPermission.ExcludedDomain.Count > 0) - { + //if (participantPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantPermission.ExcludedPerson.Count > 0) - { + //if (participantPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -219,7 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -315,6 +319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -332,6 +341,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 41959237b..2d546615d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); - if (participantRole.Alias.Count > 0) - { + //if (participantRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - if (participantRole.Definition.Count > 0) - { + //if (participantRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.HyperLink.Count > 0) - { + //if (participantRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -125,8 +129,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - if (participantRole.ParticipantPermission.Count > 0) - { + //if (participantRole.ParticipantPermission.Count > 0) + //{ writer.WriteStartArray("participantPermission"u8); foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) @@ -135,7 +139,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); - if (participantRole.Alias.Count > 0) - { + //if (participantRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - if (participantRole.Definition.Count > 0) - { + //if (participantRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedDomain.Count > 0) - { + //if (participantRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedPerson.Count > 0) - { + //if (participantRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.HyperLink.Count > 0) - { + //if (participantRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -220,8 +224,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - if (participantRole.ParticipantPermission.Count > 0) - { + //if (participantRole.ParticipantPermission.Count > 0) + //{ writer.WriteStartArray("participantPermission"u8); foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) @@ -230,7 +234,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); - if (participantRole.Alias.Count > 0) - { + //if (participantRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,13 +254,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - if (participantRole.Definition.Count > 0) - { + //if (participantRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedDomain.Count > 0) - { + //if (participantRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedPerson.Count > 0) - { + //if (participantRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.HyperLink.Count > 0) - { + //if (participantRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -304,7 +308,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -315,8 +319,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - if (participantRole.ParticipantPermission.Count > 0) - { + //if (participantRole.ParticipantPermission.Count > 0) + //{ writer.WriteStartArray("participantPermission"u8); foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) @@ -325,7 +329,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (participantRole.Alias.Count > 0) - { + //if (participantRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,13 +361,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); - if (participantRole.Definition.Count > 0) - { + //if (participantRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -372,11 +376,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedDomain.Count > 0) - { + //if (participantRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.ExcludedPerson.Count > 0) - { + //if (participantRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participantRole.HyperLink.Count > 0) - { + //if (participantRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -411,7 +415,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -422,8 +426,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); - if (participantRole.ParticipantPermission.Count > 0) - { + //if (participantRole.ParticipantPermission.Count > 0) + //{ writer.WriteStartArray("participantPermission"u8); foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) @@ -432,7 +436,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -521,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -661,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParticipantPermission && objectListParticipantPermission.Any()) { writer.WriteStartArray("participantPermission"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index 22509c97e..79cb9b9ed 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - if (participant.Domain.Count > 0) - { + //if (participant.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) @@ -90,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -110,8 +114,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - if (participant.Domain.Count > 0) - { + //if (participant.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) @@ -120,11 +124,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedDomain.Count > 0) - { + //if (participant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -133,11 +137,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedPerson.Count > 0) - { + //if (participant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -146,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - if (participant.Domain.Count > 0) - { + //if (participant.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) @@ -178,11 +182,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedDomain.Count > 0) - { + //if (participant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -191,11 +195,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedPerson.Count > 0) - { + //if (participant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -204,7 +208,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -239,8 +243,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); - if (participant.Domain.Count > 0) - { + //if (participant.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) @@ -249,11 +253,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedDomain.Count > 0) - { + //if (participant.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -262,11 +266,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (participant.ExcludedPerson.Count > 0) - { + //if (participant.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -275,7 +279,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -357,6 +361,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { writer.WriteStartArray("domain"u8); @@ -374,6 +383,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -391,6 +405,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index e35673f8b..1fbca5451 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - if (personPermission.ExcludedDomain.Count > 0) - { + //if (personPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personPermission.ExcludedPerson.Count > 0) - { + //if (personPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - if (personPermission.ExcludedDomain.Count > 0) - { + //if (personPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -150,11 +154,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personPermission.ExcludedPerson.Count > 0) - { + //if (personPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -163,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -196,8 +200,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); - if (personPermission.ExcludedDomain.Count > 0) - { + //if (personPermission.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personPermission.ExcludedPerson.Count > 0) - { + //if (personPermission.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -219,7 +223,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -315,6 +319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -332,6 +341,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index e229e7085..58c75b5e2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); - if (personRole.Alias.Count > 0) - { + //if (personRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - if (personRole.Definition.Count > 0) - { + //if (personRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.HyperLink.Count > 0) - { + //if (personRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -125,8 +129,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - if (personRole.PersonPermission.Count > 0) - { + //if (personRole.PersonPermission.Count > 0) + //{ writer.WriteStartArray("personPermission"u8); foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) @@ -135,7 +139,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); - if (personRole.Alias.Count > 0) - { + //if (personRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - if (personRole.Definition.Count > 0) - { + //if (personRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedDomain.Count > 0) - { + //if (personRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedPerson.Count > 0) - { + //if (personRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.HyperLink.Count > 0) - { + //if (personRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -220,8 +224,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - if (personRole.PersonPermission.Count > 0) - { + //if (personRole.PersonPermission.Count > 0) + //{ writer.WriteStartArray("personPermission"u8); foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) @@ -230,7 +234,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); - if (personRole.Alias.Count > 0) - { + //if (personRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,13 +254,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - if (personRole.Definition.Count > 0) - { + //if (personRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedDomain.Count > 0) - { + //if (personRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedPerson.Count > 0) - { + //if (personRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.HyperLink.Count > 0) - { + //if (personRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -304,7 +308,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -315,8 +319,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - if (personRole.PersonPermission.Count > 0) - { + //if (personRole.PersonPermission.Count > 0) + //{ writer.WriteStartArray("personPermission"u8); foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) @@ -325,7 +329,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (personRole.Alias.Count > 0) - { + //if (personRole.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,13 +361,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); - if (personRole.Definition.Count > 0) - { + //if (personRole.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) @@ -372,11 +376,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedDomain.Count > 0) - { + //if (personRole.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.ExcludedPerson.Count > 0) - { + //if (personRole.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (personRole.HyperLink.Count > 0) - { + //if (personRole.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -411,7 +415,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -422,8 +426,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); - if (personRole.PersonPermission.Count > 0) - { + //if (personRole.PersonPermission.Count > 0) + //{ writer.WriteStartArray("personPermission"u8); foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) @@ -432,7 +436,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -521,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -661,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPersonPermission && objectListPersonPermission.Any()) { writer.WriteStartArray("personPermission"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index e626ed3e1..1f080af4b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -112,8 +116,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (person.EmailAddress.Count > 0) - { + //if (person.EmailAddress.Count > 0) + //{ writer.WriteStartArray("emailAddress"u8); foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -165,8 +169,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - if (person.TelephoneNumber.Count > 0) - { + //if (person.TelephoneNumber.Count > 0) + //{ writer.WriteStartArray("telephoneNumber"u8); foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) @@ -175,11 +179,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.UserPreference.Count > 0) - { + //if (person.UserPreference.Count > 0) + //{ writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -188,7 +192,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -228,8 +232,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (person.EmailAddress.Count > 0) - { + //if (person.EmailAddress.Count > 0) + //{ writer.WriteStartArray("emailAddress"u8); foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) @@ -238,11 +242,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedDomain.Count > 0) - { + //if (person.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -251,11 +255,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedPerson.Count > 0) - { + //if (person.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -264,7 +268,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -309,8 +313,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - if (person.TelephoneNumber.Count > 0) - { + //if (person.TelephoneNumber.Count > 0) + //{ writer.WriteStartArray("telephoneNumber"u8); foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) @@ -319,11 +323,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.UserPreference.Count > 0) - { + //if (person.UserPreference.Count > 0) + //{ writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -332,7 +336,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -372,8 +376,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (person.EmailAddress.Count > 0) - { + //if (person.EmailAddress.Count > 0) + //{ writer.WriteStartArray("emailAddress"u8); foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) @@ -382,11 +386,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedDomain.Count > 0) - { + //if (person.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -395,11 +399,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedPerson.Count > 0) - { + //if (person.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -408,7 +412,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -453,8 +457,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - if (person.TelephoneNumber.Count > 0) - { + //if (person.TelephoneNumber.Count > 0) + //{ writer.WriteStartArray("telephoneNumber"u8); foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) @@ -463,13 +467,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); - if (person.UserPreference.Count > 0) - { + //if (person.UserPreference.Count > 0) + //{ writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -478,7 +482,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -529,8 +533,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (person.EmailAddress.Count > 0) - { + //if (person.EmailAddress.Count > 0) + //{ writer.WriteStartArray("emailAddress"u8); foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) @@ -539,11 +543,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedDomain.Count > 0) - { + //if (person.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -552,11 +556,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (person.ExcludedPerson.Count > 0) - { + //if (person.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -565,7 +569,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -610,8 +614,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); - if (person.TelephoneNumber.Count > 0) - { + //if (person.TelephoneNumber.Count > 0) + //{ writer.WriteStartArray("telephoneNumber"u8); foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) @@ -620,13 +624,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); - if (person.UserPreference.Count > 0) - { + //if (person.UserPreference.Count > 0) + //{ writer.WriteStartArray("userPreference"u8); foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) @@ -635,7 +639,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -755,6 +759,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListEmailAddress && objectListEmailAddress.Any()) { writer.WriteStartArray("emailAddress"u8); @@ -772,6 +781,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -789,6 +803,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1022,6 +1041,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListTelephoneNumber && objectListTelephoneNumber.Any()) { writer.WriteStartArray("telephoneNumber"u8); @@ -1057,6 +1081,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUserPreference && objectListUserPreference.Any()) { writer.WriteStartArray("userPreference"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 8092cb650..086e36429 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - if (point.ExcludedDomain.Count > 0) - { + //if (point.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (point.ExcludedPerson.Count > 0) - { + //if (point.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -123,8 +127,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - if (point.ExcludedDomain.Count > 0) - { + //if (point.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -133,11 +137,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (point.ExcludedPerson.Count > 0) - { + //if (point.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -146,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -179,8 +183,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); - if (point.ExcludedDomain.Count > 0) - { + //if (point.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -189,11 +193,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (point.ExcludedPerson.Count > 0) - { + //if (point.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -282,6 +286,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -299,6 +308,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 6248389a3..ddf16679b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); - if (possibleFiniteStateList.Alias.Count > 0) - { + //if (possibleFiniteStateList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.Category.Count > 0) - { + //if (possibleFiniteStateList.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,7 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -116,8 +120,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteStateList.Definition.Count > 0) - { + //if (possibleFiniteStateList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -126,11 +130,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.HyperLink.Count > 0) - { + //if (possibleFiniteStateList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -139,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -148,8 +152,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - if (possibleFiniteStateList.PossibleState.Count > 0) - { + //if (possibleFiniteStateList.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) @@ -158,7 +162,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); - if (possibleFiniteStateList.Alias.Count > 0) - { + //if (possibleFiniteStateList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -178,11 +182,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.Category.Count > 0) - { + //if (possibleFiniteStateList.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) @@ -191,7 +195,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -206,8 +210,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteStateList.Definition.Count > 0) - { + //if (possibleFiniteStateList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -216,11 +220,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedDomain.Count > 0) - { + //if (possibleFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -229,11 +233,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedPerson.Count > 0) - { + //if (possibleFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -242,11 +246,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.HyperLink.Count > 0) - { + //if (possibleFiniteStateList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -255,7 +259,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - if (possibleFiniteStateList.PossibleState.Count > 0) - { + //if (possibleFiniteStateList.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) @@ -276,7 +280,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -286,8 +290,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); - if (possibleFiniteStateList.Alias.Count > 0) - { + //if (possibleFiniteStateList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -296,11 +300,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.Category.Count > 0) - { + //if (possibleFiniteStateList.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) @@ -309,7 +313,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -324,8 +328,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteStateList.Definition.Count > 0) - { + //if (possibleFiniteStateList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -334,11 +338,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedDomain.Count > 0) - { + //if (possibleFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -347,11 +351,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedPerson.Count > 0) - { + //if (possibleFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -360,11 +364,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.HyperLink.Count > 0) - { + //if (possibleFiniteStateList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -373,7 +377,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -384,8 +388,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - if (possibleFiniteStateList.PossibleState.Count > 0) - { + //if (possibleFiniteStateList.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) @@ -394,7 +398,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -416,8 +420,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteStateList.Alias.Count > 0) - { + //if (possibleFiniteStateList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -426,11 +430,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.Category.Count > 0) - { + //if (possibleFiniteStateList.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) @@ -439,7 +443,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); @@ -454,8 +458,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteStateList.Definition.Count > 0) - { + //if (possibleFiniteStateList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -464,11 +468,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedDomain.Count > 0) - { + //if (possibleFiniteStateList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -477,11 +481,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.ExcludedPerson.Count > 0) - { + //if (possibleFiniteStateList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -490,11 +494,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteStateList.HyperLink.Count > 0) - { + //if (possibleFiniteStateList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -503,7 +507,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -514,8 +518,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); - if (possibleFiniteStateList.PossibleState.Count > 0) - { + //if (possibleFiniteStateList.PossibleState.Count > 0) + //{ writer.WriteStartArray("possibleState"u8); foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) @@ -524,7 +528,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -578,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -595,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -648,6 +662,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -665,6 +684,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -682,6 +706,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -699,6 +728,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -788,6 +822,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) { writer.WriteStartArray("possibleState"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index b7f0dfd42..f5599ec6c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); - if (possibleFiniteState.Alias.Count > 0) - { + //if (possibleFiniteState.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - if (possibleFiniteState.Definition.Count > 0) - { + //if (possibleFiniteState.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.HyperLink.Count > 0) - { + //if (possibleFiniteState.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -130,8 +134,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); - if (possibleFiniteState.Alias.Count > 0) - { + //if (possibleFiniteState.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -140,13 +144,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - if (possibleFiniteState.Definition.Count > 0) - { + //if (possibleFiniteState.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedDomain.Count > 0) - { + //if (possibleFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedPerson.Count > 0) - { + //if (possibleFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.HyperLink.Count > 0) - { + //if (possibleFiniteState.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -210,8 +214,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); - if (possibleFiniteState.Alias.Count > 0) - { + //if (possibleFiniteState.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - if (possibleFiniteState.Definition.Count > 0) - { + //if (possibleFiniteState.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedDomain.Count > 0) - { + //if (possibleFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedPerson.Count > 0) - { + //if (possibleFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -261,11 +265,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.HyperLink.Count > 0) - { + //if (possibleFiniteState.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -274,7 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -302,8 +306,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (possibleFiniteState.Alias.Count > 0) - { + //if (possibleFiniteState.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) @@ -312,13 +316,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); - if (possibleFiniteState.Definition.Count > 0) - { + //if (possibleFiniteState.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedDomain.Count > 0) - { + //if (possibleFiniteState.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.ExcludedPerson.Count > 0) - { + //if (possibleFiniteState.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (possibleFiniteState.HyperLink.Count > 0) - { + //if (possibleFiniteState.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -366,7 +370,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -426,6 +430,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -461,6 +470,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -478,6 +492,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -495,6 +514,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -512,6 +536,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index 32c9dc562..8baff24a1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); - if (prefixedUnit.Alias.Count > 0) - { + //if (prefixedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - if (prefixedUnit.Definition.Count > 0) - { + //if (prefixedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.HyperLink.Count > 0) - { + //if (prefixedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -132,8 +136,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); - if (prefixedUnit.Alias.Count > 0) - { + //if (prefixedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -142,13 +146,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - if (prefixedUnit.Definition.Count > 0) - { + //if (prefixedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedDomain.Count > 0) - { + //if (prefixedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedPerson.Count > 0) - { + //if (prefixedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.HyperLink.Count > 0) - { + //if (prefixedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -196,7 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -214,8 +218,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); - if (prefixedUnit.Alias.Count > 0) - { + //if (prefixedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -224,13 +228,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - if (prefixedUnit.Definition.Count > 0) - { + //if (prefixedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -239,11 +243,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedDomain.Count > 0) - { + //if (prefixedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedPerson.Count > 0) - { + //if (prefixedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.HyperLink.Count > 0) - { + //if (prefixedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -278,7 +282,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -308,8 +312,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (prefixedUnit.Alias.Count > 0) - { + //if (prefixedUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -318,13 +322,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); - if (prefixedUnit.Definition.Count > 0) - { + //if (prefixedUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -333,11 +337,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedDomain.Count > 0) - { + //if (prefixedUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -346,11 +350,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.ExcludedPerson.Count > 0) - { + //if (prefixedUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -359,11 +363,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (prefixedUnit.HyperLink.Count > 0) - { + //if (prefixedUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -372,7 +376,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -434,6 +438,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -469,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -486,6 +500,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -503,6 +522,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -520,6 +544,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index 2746ad99e..defcf4849 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -82,8 +86,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.Domain.Count > 0) - { + //if (publication.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) @@ -92,13 +96,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); - if (publication.PublishedParameter.Count > 0) - { + //if (publication.PublishedParameter.Count > 0) + //{ writer.WriteStartArray("publishedParameter"u8); foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) @@ -107,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -119,8 +123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.Domain.Count > 0) - { + //if (publication.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedDomain.Count > 0) - { + //if (publication.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedPerson.Count > 0) - { + //if (publication.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -155,15 +159,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.PublishedParameter.Count > 0) - { + //if (publication.PublishedParameter.Count > 0) + //{ writer.WriteStartArray("publishedParameter"u8); foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) @@ -172,7 +176,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -184,8 +188,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.Domain.Count > 0) - { + //if (publication.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) @@ -194,11 +198,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedDomain.Count > 0) - { + //if (publication.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -207,11 +211,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedPerson.Count > 0) - { + //if (publication.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -220,15 +224,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.PublishedParameter.Count > 0) - { + //if (publication.PublishedParameter.Count > 0) + //{ writer.WriteStartArray("publishedParameter"u8); foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) @@ -237,7 +241,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -262,8 +266,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.Domain.Count > 0) - { + //if (publication.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) @@ -272,11 +276,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedDomain.Count > 0) - { + //if (publication.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -285,11 +289,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (publication.ExcludedPerson.Count > 0) - { + //if (publication.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -298,15 +302,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (publication.PublishedParameter.Count > 0) - { + //if (publication.PublishedParameter.Count > 0) + //{ writer.WriteStartArray("publishedParameter"u8); foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) @@ -315,7 +319,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -403,6 +407,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { writer.WriteStartArray("domain"u8); @@ -420,6 +429,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -437,6 +451,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -490,6 +509,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPublishedParameter && objectListPublishedParameter.Any()) { writer.WriteStartArray("publishedParameter"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 3a99188b7..6313a8919 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - if (quantityKindFactor.ExcludedDomain.Count > 0) - { + //if (quantityKindFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (quantityKindFactor.ExcludedPerson.Count > 0) - { + //if (quantityKindFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - if (quantityKindFactor.ExcludedDomain.Count > 0) - { + //if (quantityKindFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (quantityKindFactor.ExcludedPerson.Count > 0) - { + //if (quantityKindFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); - if (quantityKindFactor.ExcludedDomain.Count > 0) - { + //if (quantityKindFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (quantityKindFactor.ExcludedPerson.Count > 0) - { + //if (quantityKindFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index c0433aa67..acba9b4e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); - if (ratioScale.Alias.Count > 0) - { + //if (ratioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - if (ratioScale.Definition.Count > 0) - { + //if (ratioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.HyperLink.Count > 0) - { + //if (ratioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - if (ratioScale.MappingToReferenceScale.Count > 0) - { + //if (ratioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -158,8 +162,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - if (ratioScale.ValueDefinition.Count > 0) - { + //if (ratioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -168,14 +172,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); - if (ratioScale.Alias.Count > 0) - { + //if (ratioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -184,13 +188,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - if (ratioScale.Definition.Count > 0) - { + //if (ratioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -199,11 +203,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedDomain.Count > 0) - { + //if (ratioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -212,11 +216,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedPerson.Count > 0) - { + //if (ratioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -225,11 +229,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.HyperLink.Count > 0) - { + //if (ratioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -238,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -249,8 +253,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - if (ratioScale.MappingToReferenceScale.Count > 0) - { + //if (ratioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -259,7 +263,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -282,8 +286,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - if (ratioScale.ValueDefinition.Count > 0) - { + //if (ratioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -292,14 +296,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); - if (ratioScale.Alias.Count > 0) - { + //if (ratioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -308,13 +312,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - if (ratioScale.Definition.Count > 0) - { + //if (ratioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -323,11 +327,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedDomain.Count > 0) - { + //if (ratioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -336,11 +340,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedPerson.Count > 0) - { + //if (ratioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -349,11 +353,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.HyperLink.Count > 0) - { + //if (ratioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -362,7 +366,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -373,8 +377,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - if (ratioScale.MappingToReferenceScale.Count > 0) - { + //if (ratioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -383,7 +387,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -408,8 +412,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - if (ratioScale.ValueDefinition.Count > 0) - { + //if (ratioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -418,7 +422,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -434,8 +438,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (ratioScale.Alias.Count > 0) - { + //if (ratioScale.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) @@ -444,13 +448,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); - if (ratioScale.Definition.Count > 0) - { + //if (ratioScale.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) @@ -459,11 +463,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedDomain.Count > 0) - { + //if (ratioScale.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -472,11 +476,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.ExcludedPerson.Count > 0) - { + //if (ratioScale.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -485,11 +489,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ratioScale.HyperLink.Count > 0) - { + //if (ratioScale.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -498,7 +502,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -509,8 +513,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); - if (ratioScale.MappingToReferenceScale.Count > 0) - { + //if (ratioScale.MappingToReferenceScale.Count > 0) + //{ writer.WriteStartArray("mappingToReferenceScale"u8); foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) @@ -519,7 +523,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -544,8 +548,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); - if (ratioScale.ValueDefinition.Count > 0) - { + //if (ratioScale.ValueDefinition.Count > 0) + //{ writer.WriteStartArray("valueDefinition"u8); foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) @@ -554,7 +558,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -602,6 +606,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -637,6 +646,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -654,6 +668,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -671,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -688,6 +712,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -777,6 +806,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) { writer.WriteStartArray("mappingToReferenceScale"u8); @@ -992,6 +1026,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) { writer.WriteStartArray("valueDefinition"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index c158b922c..007650018 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); - if (referenceSource.Alias.Count > 0) - { + //if (referenceSource.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - if (referenceSource.Category.Count > 0) - { + //if (referenceSource.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,13 +107,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - if (referenceSource.Definition.Count > 0) - { + //if (referenceSource.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.HyperLink.Count > 0) - { + //if (referenceSource.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -195,8 +199,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); - if (referenceSource.Alias.Count > 0) - { + //if (referenceSource.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -205,13 +209,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - if (referenceSource.Category.Count > 0) - { + //if (referenceSource.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) @@ -220,13 +224,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - if (referenceSource.Definition.Count > 0) - { + //if (referenceSource.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedDomain.Count > 0) - { + //if (referenceSource.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedPerson.Count > 0) - { + //if (referenceSource.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -261,11 +265,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.HyperLink.Count > 0) - { + //if (referenceSource.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -274,7 +278,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -340,8 +344,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); - if (referenceSource.Alias.Count > 0) - { + //if (referenceSource.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -350,13 +354,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - if (referenceSource.Category.Count > 0) - { + //if (referenceSource.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) @@ -365,13 +369,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - if (referenceSource.Definition.Count > 0) - { + //if (referenceSource.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) @@ -380,11 +384,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedDomain.Count > 0) - { + //if (referenceSource.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -393,11 +397,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedPerson.Count > 0) - { + //if (referenceSource.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -406,11 +410,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.HyperLink.Count > 0) - { + //if (referenceSource.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -419,7 +423,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -497,8 +501,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (referenceSource.Alias.Count > 0) - { + //if (referenceSource.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) @@ -507,13 +511,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); - if (referenceSource.Category.Count > 0) - { + //if (referenceSource.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) @@ -522,13 +526,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); - if (referenceSource.Definition.Count > 0) - { + //if (referenceSource.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) @@ -537,11 +541,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedDomain.Count > 0) - { + //if (referenceSource.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -550,11 +554,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.ExcludedPerson.Count > 0) - { + //if (referenceSource.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -563,11 +567,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referenceSource.HyperLink.Count > 0) - { + //if (referenceSource.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -576,7 +580,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -686,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -721,6 +730,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -756,6 +770,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -773,6 +792,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -790,6 +814,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -807,6 +836,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index af4f1f55a..6e9a92986 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); - if (referencerRule.Alias.Count > 0) - { + //if (referencerRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - if (referencerRule.Definition.Count > 0) - { + //if (referencerRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.HyperLink.Count > 0) - { + //if (referencerRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - if (referencerRule.ReferencedCategory.Count > 0) - { + //if (referencerRule.ReferencedCategory.Count > 0) + //{ writer.WriteStartArray("referencedCategory"u8); foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) @@ -139,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -151,8 +155,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); - if (referencerRule.Alias.Count > 0) - { + //if (referencerRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -161,13 +165,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - if (referencerRule.Definition.Count > 0) - { + //if (referencerRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedDomain.Count > 0) - { + //if (referencerRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -189,11 +193,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedPerson.Count > 0) - { + //if (referencerRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -202,11 +206,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.HyperLink.Count > 0) - { + //if (referencerRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -215,7 +219,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -230,8 +234,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - if (referencerRule.ReferencedCategory.Count > 0) - { + //if (referencerRule.ReferencedCategory.Count > 0) + //{ writer.WriteStartArray("referencedCategory"u8); foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) @@ -240,7 +244,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -252,8 +256,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); - if (referencerRule.Alias.Count > 0) - { + //if (referencerRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -262,13 +266,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - if (referencerRule.Definition.Count > 0) - { + //if (referencerRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -277,11 +281,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedDomain.Count > 0) - { + //if (referencerRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -290,11 +294,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedPerson.Count > 0) - { + //if (referencerRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -303,11 +307,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.HyperLink.Count > 0) - { + //if (referencerRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -316,7 +320,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -331,8 +335,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - if (referencerRule.ReferencedCategory.Count > 0) - { + //if (referencerRule.ReferencedCategory.Count > 0) + //{ writer.WriteStartArray("referencedCategory"u8); foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) @@ -341,7 +345,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -365,8 +369,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (referencerRule.Alias.Count > 0) - { + //if (referencerRule.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) @@ -375,13 +379,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); - if (referencerRule.Definition.Count > 0) - { + //if (referencerRule.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) @@ -390,11 +394,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedDomain.Count > 0) - { + //if (referencerRule.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -403,11 +407,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.ExcludedPerson.Count > 0) - { + //if (referencerRule.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -416,11 +420,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (referencerRule.HyperLink.Count > 0) - { + //if (referencerRule.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -429,7 +433,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -444,8 +448,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); - if (referencerRule.ReferencedCategory.Count > 0) - { + //if (referencerRule.ReferencedCategory.Count > 0) + //{ writer.WriteStartArray("referencedCategory"u8); foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) @@ -454,7 +458,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -510,6 +514,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -545,6 +554,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -562,6 +576,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -579,6 +598,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -596,6 +620,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -721,6 +750,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListReferencedCategory && objectListReferencedCategory.Any()) { writer.WriteStartArray("referencedCategory"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index 95f88bdd9..098223f42 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -105,8 +109,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - if (relationalExpression.ExcludedDomain.Count > 0) - { + //if (relationalExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -115,11 +119,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationalExpression.ExcludedPerson.Count > 0) - { + //if (relationalExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -128,7 +132,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -158,8 +162,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - if (relationalExpression.ExcludedDomain.Count > 0) - { + //if (relationalExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationalExpression.ExcludedPerson.Count > 0) - { + //if (relationalExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -181,7 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); - if (relationalExpression.ExcludedDomain.Count > 0) - { + //if (relationalExpression.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -234,11 +238,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationalExpression.ExcludedPerson.Count > 0) - { + //if (relationalExpression.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -337,6 +341,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -354,6 +363,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 82c62a34f..7862656db 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - if (relationshipParameterValue.ExcludedDomain.Count > 0) - { + //if (relationshipParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationshipParameterValue.ExcludedPerson.Count > 0) - { + //if (relationshipParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -131,8 +135,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - if (relationshipParameterValue.ExcludedDomain.Count > 0) - { + //if (relationshipParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -141,11 +145,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationshipParameterValue.ExcludedPerson.Count > 0) - { + //if (relationshipParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -154,7 +158,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -195,8 +199,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); - if (relationshipParameterValue.ExcludedDomain.Count > 0) - { + //if (relationshipParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -205,11 +209,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (relationshipParameterValue.ExcludedPerson.Count > 0) - { + //if (relationshipParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -218,7 +222,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -306,6 +310,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -323,6 +332,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 1a188619d..70884182e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); - if (requestForDeviation.ApprovedBy.Count > 0) - { + //if (requestForDeviation.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - if (requestForDeviation.Category.Count > 0) - { + //if (requestForDeviation.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForDeviation.Discussion.Count > 0) - { + //if (requestForDeviation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -124,11 +128,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedDomain.Count > 0) - { + //if (requestForDeviation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -137,11 +141,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedPerson.Count > 0) - { + //if (requestForDeviation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForDeviation.RelatedThing.Count > 0) - { + //if (requestForDeviation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -181,15 +185,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - if (requestForDeviation.SourceAnnotation.Count > 0) - { + //if (requestForDeviation.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -208,8 +212,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); - if (requestForDeviation.ApprovedBy.Count > 0) - { + //if (requestForDeviation.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -218,13 +222,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - if (requestForDeviation.Category.Count > 0) - { + //if (requestForDeviation.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) @@ -233,7 +237,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForDeviation.Discussion.Count > 0) - { + //if (requestForDeviation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedDomain.Count > 0) - { + //if (requestForDeviation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -267,11 +271,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedPerson.Count > 0) - { + //if (requestForDeviation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -280,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -301,8 +305,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForDeviation.RelatedThing.Count > 0) - { + //if (requestForDeviation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -311,15 +315,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - if (requestForDeviation.SourceAnnotation.Count > 0) - { + //if (requestForDeviation.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -328,7 +332,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -350,8 +354,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForDeviation.ApprovedBy.Count > 0) - { + //if (requestForDeviation.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -360,13 +364,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); - if (requestForDeviation.Category.Count > 0) - { + //if (requestForDeviation.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) @@ -375,7 +379,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForDeviation.Discussion.Count > 0) - { + //if (requestForDeviation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -396,11 +400,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedDomain.Count > 0) - { + //if (requestForDeviation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForDeviation.ExcludedPerson.Count > 0) - { + //if (requestForDeviation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -422,7 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForDeviation.RelatedThing.Count > 0) - { + //if (requestForDeviation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -453,15 +457,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); - if (requestForDeviation.SourceAnnotation.Count > 0) - { + //if (requestForDeviation.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -470,7 +474,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -524,6 +528,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -559,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -648,6 +662,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -665,6 +684,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -682,6 +706,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -789,6 +818,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -842,6 +876,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index 2b0e14484..fb3641b13 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); - if (requestForWaiver.ApprovedBy.Count > 0) - { + //if (requestForWaiver.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - if (requestForWaiver.Category.Count > 0) - { + //if (requestForWaiver.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForWaiver.Discussion.Count > 0) - { + //if (requestForWaiver.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -124,11 +128,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedDomain.Count > 0) - { + //if (requestForWaiver.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -137,11 +141,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedPerson.Count > 0) - { + //if (requestForWaiver.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForWaiver.RelatedThing.Count > 0) - { + //if (requestForWaiver.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -181,15 +185,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - if (requestForWaiver.SourceAnnotation.Count > 0) - { + //if (requestForWaiver.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -208,8 +212,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); - if (requestForWaiver.ApprovedBy.Count > 0) - { + //if (requestForWaiver.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -218,13 +222,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - if (requestForWaiver.Category.Count > 0) - { + //if (requestForWaiver.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) @@ -233,7 +237,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForWaiver.Discussion.Count > 0) - { + //if (requestForWaiver.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedDomain.Count > 0) - { + //if (requestForWaiver.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -267,11 +271,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedPerson.Count > 0) - { + //if (requestForWaiver.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -280,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -301,8 +305,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForWaiver.RelatedThing.Count > 0) - { + //if (requestForWaiver.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -311,15 +315,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - if (requestForWaiver.SourceAnnotation.Count > 0) - { + //if (requestForWaiver.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -328,7 +332,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -350,8 +354,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForWaiver.ApprovedBy.Count > 0) - { + //if (requestForWaiver.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -360,13 +364,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); - if (requestForWaiver.Category.Count > 0) - { + //if (requestForWaiver.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) @@ -375,7 +379,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -386,8 +390,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (requestForWaiver.Discussion.Count > 0) - { + //if (requestForWaiver.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -396,11 +400,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedDomain.Count > 0) - { + //if (requestForWaiver.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requestForWaiver.ExcludedPerson.Count > 0) - { + //if (requestForWaiver.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -422,7 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -443,8 +447,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requestForWaiver.RelatedThing.Count > 0) - { + //if (requestForWaiver.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -453,15 +457,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); - if (requestForWaiver.SourceAnnotation.Count > 0) - { + //if (requestForWaiver.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -470,7 +474,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -524,6 +528,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -559,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -648,6 +662,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -665,6 +684,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -682,6 +706,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -789,6 +818,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -842,6 +876,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 03da10358..2b0396b16 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); - if (requirement.Alias.Count > 0) - { + //if (requirement.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.Category.Count > 0) - { + //if (requirement.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - if (requirement.Definition.Count > 0) - { + //if (requirement.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("group"u8); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirement.HyperLink.Count > 0) - { + //if (requirement.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -139,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -150,8 +154,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - if (requirement.ParameterValue.Count > 0) - { + //if (requirement.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -160,11 +164,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ParametricConstraint.Count > 0) - { + //if (requirement.ParametricConstraint.Count > 0) + //{ writer.WriteStartArray("parametricConstraint"u8); foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) @@ -173,7 +177,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -183,8 +187,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); - if (requirement.Alias.Count > 0) - { + //if (requirement.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) @@ -193,11 +197,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.Category.Count > 0) - { + //if (requirement.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) @@ -206,13 +210,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - if (requirement.Definition.Count > 0) - { + //if (requirement.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) @@ -221,11 +225,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedDomain.Count > 0) - { + //if (requirement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -234,11 +238,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedPerson.Count > 0) - { + //if (requirement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("group"u8); @@ -260,8 +264,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirement.HyperLink.Count > 0) - { + //if (requirement.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -270,7 +274,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -283,8 +287,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - if (requirement.ParameterValue.Count > 0) - { + //if (requirement.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -293,11 +297,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ParametricConstraint.Count > 0) - { + //if (requirement.ParametricConstraint.Count > 0) + //{ writer.WriteStartArray("parametricConstraint"u8); foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) @@ -306,7 +310,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -316,8 +320,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); - if (requirement.Alias.Count > 0) - { + //if (requirement.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) @@ -326,11 +330,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.Category.Count > 0) - { + //if (requirement.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) @@ -339,13 +343,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - if (requirement.Definition.Count > 0) - { + //if (requirement.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) @@ -354,11 +358,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedDomain.Count > 0) - { + //if (requirement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -367,11 +371,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedPerson.Count > 0) - { + //if (requirement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -380,7 +384,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("group"u8); @@ -393,8 +397,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirement.HyperLink.Count > 0) - { + //if (requirement.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -403,7 +407,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -416,8 +420,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - if (requirement.ParameterValue.Count > 0) - { + //if (requirement.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -426,11 +430,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ParametricConstraint.Count > 0) - { + //if (requirement.ParametricConstraint.Count > 0) + //{ writer.WriteStartArray("parametricConstraint"u8); foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) @@ -439,7 +443,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -461,8 +465,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirement.Alias.Count > 0) - { + //if (requirement.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) @@ -471,11 +475,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.Category.Count > 0) - { + //if (requirement.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) @@ -484,13 +488,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); - if (requirement.Definition.Count > 0) - { + //if (requirement.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) @@ -499,11 +503,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedDomain.Count > 0) - { + //if (requirement.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -512,11 +516,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ExcludedPerson.Count > 0) - { + //if (requirement.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -525,7 +529,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("group"u8); @@ -538,8 +542,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirement.HyperLink.Count > 0) - { + //if (requirement.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -548,7 +552,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -561,8 +565,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); - if (requirement.ParameterValue.Count > 0) - { + //if (requirement.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -571,11 +575,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirement.ParametricConstraint.Count > 0) - { + //if (requirement.ParametricConstraint.Count > 0) + //{ writer.WriteStartArray("parametricConstraint"u8); foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) @@ -584,7 +588,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -638,6 +642,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -655,6 +664,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -690,6 +704,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -707,6 +726,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -724,6 +748,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -759,6 +788,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -866,6 +900,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { writer.WriteStartArray("parameterValue"u8); @@ -883,6 +922,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParametricConstraint && objectListParametricConstraint.Any()) { writer.WriteStartArray("parametricConstraint"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 89ff37048..40497527b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -131,8 +135,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -141,11 +145,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -154,7 +158,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -195,8 +199,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); - if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -205,11 +209,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - { + //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -218,7 +222,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -306,6 +310,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -323,6 +332,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index a63442b82..91e80788b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); - if (requirementsGroup.Alias.Count > 0) - { + //if (requirementsGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - if (requirementsGroup.Definition.Count > 0) - { + //if (requirementsGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Group.Count > 0) - { + //if (requirementsGroup.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.HyperLink.Count > 0) - { + //if (requirementsGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); - if (requirementsGroup.Alias.Count > 0) - { + //if (requirementsGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Category.Count > 0) - { + //if (requirementsGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -168,13 +172,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - if (requirementsGroup.Definition.Count > 0) - { + //if (requirementsGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedDomain.Count > 0) - { + //if (requirementsGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedPerson.Count > 0) - { + //if (requirementsGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Group.Count > 0) - { + //if (requirementsGroup.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.HyperLink.Count > 0) - { + //if (requirementsGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -235,7 +239,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -246,8 +250,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - if (requirementsGroup.ParameterValue.Count > 0) - { + //if (requirementsGroup.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -256,7 +260,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); - if (requirementsGroup.Alias.Count > 0) - { + //if (requirementsGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Category.Count > 0) - { + //if (requirementsGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -289,13 +293,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - if (requirementsGroup.Definition.Count > 0) - { + //if (requirementsGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -304,11 +308,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedDomain.Count > 0) - { + //if (requirementsGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -317,11 +321,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedPerson.Count > 0) - { + //if (requirementsGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -330,11 +334,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Group.Count > 0) - { + //if (requirementsGroup.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) @@ -343,11 +347,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.HyperLink.Count > 0) - { + //if (requirementsGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -356,7 +360,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -367,8 +371,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - if (requirementsGroup.ParameterValue.Count > 0) - { + //if (requirementsGroup.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -377,7 +381,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -399,8 +403,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirementsGroup.Alias.Count > 0) - { + //if (requirementsGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Category.Count > 0) - { + //if (requirementsGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -422,13 +426,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); - if (requirementsGroup.Definition.Count > 0) - { + //if (requirementsGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -437,11 +441,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedDomain.Count > 0) - { + //if (requirementsGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -450,11 +454,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.ExcludedPerson.Count > 0) - { + //if (requirementsGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -463,11 +467,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.Group.Count > 0) - { + //if (requirementsGroup.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) @@ -476,11 +480,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsGroup.HyperLink.Count > 0) - { + //if (requirementsGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -489,7 +493,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -500,8 +504,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); - if (requirementsGroup.ParameterValue.Count > 0) - { + //if (requirementsGroup.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -510,7 +514,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -564,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -581,6 +590,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -616,6 +630,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -633,6 +652,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -650,6 +674,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -667,6 +696,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGroup && objectListGroup.Any()) { writer.WriteStartArray("group"u8); @@ -684,6 +718,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -773,6 +812,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { writer.WriteStartArray("parameterValue"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 31939fb0f..4a15a0bf3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); - if (requirementsSpecification.Alias.Count > 0) - { + //if (requirementsSpecification.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - if (requirementsSpecification.Definition.Count > 0) - { + //if (requirementsSpecification.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Group.Count > 0) - { + //if (requirementsSpecification.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.HyperLink.Count > 0) - { + //if (requirementsSpecification.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - if (requirementsSpecification.Requirement.Count > 0) - { + //if (requirementsSpecification.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -160,8 +164,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); - if (requirementsSpecification.Alias.Count > 0) - { + //if (requirementsSpecification.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Category.Count > 0) - { + //if (requirementsSpecification.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) @@ -183,13 +187,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - if (requirementsSpecification.Definition.Count > 0) - { + //if (requirementsSpecification.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedDomain.Count > 0) - { + //if (requirementsSpecification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedPerson.Count > 0) - { + //if (requirementsSpecification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -224,11 +228,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Group.Count > 0) - { + //if (requirementsSpecification.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) @@ -237,11 +241,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.HyperLink.Count > 0) - { + //if (requirementsSpecification.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -250,7 +254,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -263,8 +267,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - if (requirementsSpecification.ParameterValue.Count > 0) - { + //if (requirementsSpecification.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -273,11 +277,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Requirement.Count > 0) - { + //if (requirementsSpecification.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -286,7 +290,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -296,8 +300,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); - if (requirementsSpecification.Alias.Count > 0) - { + //if (requirementsSpecification.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) @@ -306,11 +310,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Category.Count > 0) - { + //if (requirementsSpecification.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) @@ -319,13 +323,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - if (requirementsSpecification.Definition.Count > 0) - { + //if (requirementsSpecification.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) @@ -334,11 +338,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedDomain.Count > 0) - { + //if (requirementsSpecification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -347,11 +351,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedPerson.Count > 0) - { + //if (requirementsSpecification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -360,11 +364,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Group.Count > 0) - { + //if (requirementsSpecification.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) @@ -373,11 +377,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.HyperLink.Count > 0) - { + //if (requirementsSpecification.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -386,7 +390,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -399,8 +403,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - if (requirementsSpecification.ParameterValue.Count > 0) - { + //if (requirementsSpecification.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -409,11 +413,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Requirement.Count > 0) - { + //if (requirementsSpecification.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -422,7 +426,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -444,8 +448,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (requirementsSpecification.Alias.Count > 0) - { + //if (requirementsSpecification.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) @@ -454,11 +458,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Category.Count > 0) - { + //if (requirementsSpecification.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) @@ -467,13 +471,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); - if (requirementsSpecification.Definition.Count > 0) - { + //if (requirementsSpecification.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) @@ -482,11 +486,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedDomain.Count > 0) - { + //if (requirementsSpecification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -495,11 +499,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.ExcludedPerson.Count > 0) - { + //if (requirementsSpecification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -508,11 +512,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Group.Count > 0) - { + //if (requirementsSpecification.Group.Count > 0) + //{ writer.WriteStartArray("group"u8); foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) @@ -521,11 +525,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.HyperLink.Count > 0) - { + //if (requirementsSpecification.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -534,7 +538,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -547,8 +551,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); - if (requirementsSpecification.ParameterValue.Count > 0) - { + //if (requirementsSpecification.ParameterValue.Count > 0) + //{ writer.WriteStartArray("parameterValue"u8); foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) @@ -557,11 +561,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (requirementsSpecification.Requirement.Count > 0) - { + //if (requirementsSpecification.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -570,7 +574,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -624,6 +628,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -641,6 +650,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -676,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -693,6 +712,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -710,6 +734,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -727,6 +756,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGroup && objectListGroup.Any()) { writer.WriteStartArray("group"u8); @@ -744,6 +778,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -851,6 +890,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) { writer.WriteStartArray("parameterValue"u8); @@ -868,6 +912,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) { writer.WriteStartArray("requirement"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index 70bd29ba4..8a4c563e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); - if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - { + //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - if (reviewItemDiscrepancy.Category.Count > 0) - { + //if (reviewItemDiscrepancy.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (reviewItemDiscrepancy.Discussion.Count > 0) - { + //if (reviewItemDiscrepancy.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -124,11 +128,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -137,11 +141,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (reviewItemDiscrepancy.RelatedThing.Count > 0) - { + //if (reviewItemDiscrepancy.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -181,15 +185,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - if (reviewItemDiscrepancy.Solution.Count > 0) - { + //if (reviewItemDiscrepancy.Solution.Count > 0) + //{ writer.WriteStartArray("solution"u8); foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - { + //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -221,8 +225,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); - if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - { + //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -231,13 +235,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - if (reviewItemDiscrepancy.Category.Count > 0) - { + //if (reviewItemDiscrepancy.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) @@ -246,7 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -257,8 +261,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (reviewItemDiscrepancy.Discussion.Count > 0) - { + //if (reviewItemDiscrepancy.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -267,11 +271,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -280,11 +284,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -293,7 +297,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -314,8 +318,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (reviewItemDiscrepancy.RelatedThing.Count > 0) - { + //if (reviewItemDiscrepancy.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -324,15 +328,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - if (reviewItemDiscrepancy.Solution.Count > 0) - { + //if (reviewItemDiscrepancy.Solution.Count > 0) + //{ writer.WriteStartArray("solution"u8); foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) @@ -341,11 +345,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - { + //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -354,7 +358,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -376,8 +380,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - { + //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) + //{ writer.WriteStartArray("approvedBy"u8); foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) @@ -386,13 +390,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); - if (reviewItemDiscrepancy.Category.Count > 0) - { + //if (reviewItemDiscrepancy.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) @@ -401,7 +405,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -412,8 +416,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (reviewItemDiscrepancy.Discussion.Count > 0) - { + //if (reviewItemDiscrepancy.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -422,11 +426,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -435,11 +439,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - { + //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -448,7 +452,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -469,8 +473,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (reviewItemDiscrepancy.RelatedThing.Count > 0) - { + //if (reviewItemDiscrepancy.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -479,15 +483,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); - if (reviewItemDiscrepancy.Solution.Count > 0) - { + //if (reviewItemDiscrepancy.Solution.Count > 0) + //{ writer.WriteStartArray("solution"u8); foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) @@ -496,11 +500,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - { + //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) + //{ writer.WriteStartArray("sourceAnnotation"u8); foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) @@ -509,7 +513,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -563,6 +567,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) { writer.WriteStartArray("approvedBy"u8); @@ -598,6 +607,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -687,6 +701,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -704,6 +723,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -721,6 +745,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -828,6 +857,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); @@ -881,6 +915,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSolution && objectListSolution.Any()) { writer.WriteStartArray("solution"u8); @@ -898,6 +937,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) { writer.WriteStartArray("sourceAnnotation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index ba7f87a50..9431a2b6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); - if (ruleVerificationList.Alias.Count > 0) - { + //if (ruleVerificationList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - if (ruleVerificationList.Definition.Count > 0) - { + //if (ruleVerificationList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.HyperLink.Count > 0) - { + //if (ruleVerificationList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -127,8 +131,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - if (ruleVerificationList.RuleVerification.Count > 0) - { + //if (ruleVerificationList.RuleVerification.Count > 0) + //{ writer.WriteStartArray("ruleVerification"u8); foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) @@ -137,7 +141,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -145,8 +149,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); - if (ruleVerificationList.Alias.Count > 0) - { + //if (ruleVerificationList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -155,13 +159,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - if (ruleVerificationList.Definition.Count > 0) - { + //if (ruleVerificationList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedDomain.Count > 0) - { + //if (ruleVerificationList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedPerson.Count > 0) - { + //if (ruleVerificationList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.HyperLink.Count > 0) - { + //if (ruleVerificationList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -222,8 +226,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - if (ruleVerificationList.RuleVerification.Count > 0) - { + //if (ruleVerificationList.RuleVerification.Count > 0) + //{ writer.WriteStartArray("ruleVerification"u8); foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) @@ -232,7 +236,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -240,8 +244,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); - if (ruleVerificationList.Alias.Count > 0) - { + //if (ruleVerificationList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -250,13 +254,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - if (ruleVerificationList.Definition.Count > 0) - { + //if (ruleVerificationList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedDomain.Count > 0) - { + //if (ruleVerificationList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -278,11 +282,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedPerson.Count > 0) - { + //if (ruleVerificationList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -291,11 +295,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.HyperLink.Count > 0) - { + //if (ruleVerificationList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -304,7 +308,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -317,8 +321,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - if (ruleVerificationList.RuleVerification.Count > 0) - { + //if (ruleVerificationList.RuleVerification.Count > 0) + //{ writer.WriteStartArray("ruleVerification"u8); foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) @@ -327,7 +331,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -347,8 +351,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (ruleVerificationList.Alias.Count > 0) - { + //if (ruleVerificationList.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) @@ -357,13 +361,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); - if (ruleVerificationList.Definition.Count > 0) - { + //if (ruleVerificationList.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) @@ -372,11 +376,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedDomain.Count > 0) - { + //if (ruleVerificationList.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -385,11 +389,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.ExcludedPerson.Count > 0) - { + //if (ruleVerificationList.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -398,11 +402,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleVerificationList.HyperLink.Count > 0) - { + //if (ruleVerificationList.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -411,7 +415,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -424,8 +428,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); - if (ruleVerificationList.RuleVerification.Count > 0) - { + //if (ruleVerificationList.RuleVerification.Count > 0) + //{ writer.WriteStartArray("ruleVerification"u8); foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) @@ -434,7 +438,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -486,6 +490,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -521,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -538,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -555,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -572,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -679,6 +708,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRuleVerification && objectListRuleVerification.Any()) { writer.WriteStartArray("ruleVerification"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index 8b4e5c707..3e74e5642 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); - if (ruleViolation.ViolatingThing.Count > 0) - { + //if (ruleViolation.ViolatingThing.Count > 0) + //{ writer.WriteStartArray("violatingThing"u8); foreach(var violatingThingItem in ruleViolation.ViolatingThing) @@ -96,7 +100,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -106,8 +110,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - if (ruleViolation.ExcludedDomain.Count > 0) - { + //if (ruleViolation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleViolation.ExcludedPerson.Count > 0) - { + //if (ruleViolation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); - if (ruleViolation.ViolatingThing.Count > 0) - { + //if (ruleViolation.ViolatingThing.Count > 0) + //{ writer.WriteStartArray("violatingThing"u8); foreach(var violatingThingItem in ruleViolation.ViolatingThing) @@ -148,7 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -158,8 +162,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - if (ruleViolation.ExcludedDomain.Count > 0) - { + //if (ruleViolation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleViolation.ExcludedPerson.Count > 0) - { + //if (ruleViolation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -181,7 +185,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -192,8 +196,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); - if (ruleViolation.ViolatingThing.Count > 0) - { + //if (ruleViolation.ViolatingThing.Count > 0) + //{ writer.WriteStartArray("violatingThing"u8); foreach(var violatingThingItem in ruleViolation.ViolatingThing) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -223,8 +227,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); - if (ruleViolation.ExcludedDomain.Count > 0) - { + //if (ruleViolation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -233,11 +237,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (ruleViolation.ExcludedPerson.Count > 0) - { + //if (ruleViolation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -246,7 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -257,8 +261,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); - if (ruleViolation.ViolatingThing.Count > 0) - { + //if (ruleViolation.ViolatingThing.Count > 0) + //{ writer.WriteStartArray("violatingThing"u8); foreach(var violatingThingItem in ruleViolation.ViolatingThing) @@ -267,7 +271,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -351,6 +355,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -368,6 +377,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -457,6 +471,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListViolatingThing && objectListViolatingThing.Any()) { writer.WriteStartArray("violatingThing"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index bfb4a6843..7d88b04bc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); - if (sampledFunctionParameterType.Alias.Count > 0) - { + //if (sampledFunctionParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.Category.Count > 0) - { + //if (sampledFunctionParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - if (sampledFunctionParameterType.Definition.Count > 0) - { + //if (sampledFunctionParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("degreeOfInterpolation"u8); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (sampledFunctionParameterType.DependentParameterType.Count > 0) - { + //if (sampledFunctionParameterType.DependentParameterType.Count > 0) + //{ writer.WriteStartArray("dependentParameterType"u8); foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) @@ -139,11 +143,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.ExcludedDomain.Count > 0) - { + //if (sampledFunctionParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -152,11 +156,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.ExcludedPerson.Count > 0) - { + //if (sampledFunctionParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -165,11 +169,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.HyperLink.Count > 0) - { + //if (sampledFunctionParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -178,13 +182,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); - if (sampledFunctionParameterType.IndependentParameterType.Count > 0) - { + //if (sampledFunctionParameterType.IndependentParameterType.Count > 0) + //{ writer.WriteStartArray("independentParameterType"u8); foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) @@ -193,7 +197,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -224,8 +228,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (sampledFunctionParameterType.Alias.Count > 0) - { + //if (sampledFunctionParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -234,11 +238,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.Category.Count > 0) - { + //if (sampledFunctionParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -247,13 +251,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); - if (sampledFunctionParameterType.Definition.Count > 0) - { + //if (sampledFunctionParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -262,7 +266,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("degreeOfInterpolation"u8); @@ -275,8 +279,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (sampledFunctionParameterType.DependentParameterType.Count > 0) - { + //if (sampledFunctionParameterType.DependentParameterType.Count > 0) + //{ writer.WriteStartArray("dependentParameterType"u8); foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) @@ -285,11 +289,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.ExcludedDomain.Count > 0) - { + //if (sampledFunctionParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -298,11 +302,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.ExcludedPerson.Count > 0) - { + //if (sampledFunctionParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -311,11 +315,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sampledFunctionParameterType.HyperLink.Count > 0) - { + //if (sampledFunctionParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -324,13 +328,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); - if (sampledFunctionParameterType.IndependentParameterType.Count > 0) - { + //if (sampledFunctionParameterType.IndependentParameterType.Count > 0) + //{ writer.WriteStartArray("independentParameterType"u8); foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) @@ -339,7 +343,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -402,6 +406,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -419,6 +428,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -454,6 +468,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -489,6 +508,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDependentParameterType && objectListDependentParameterType.Any()) { writer.WriteStartArray("dependentParameterType"u8); @@ -506,6 +530,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -523,6 +552,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -540,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -575,6 +614,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListIndependentParameterType && objectListIndependentParameterType.Any()) { writer.WriteStartArray("independentParameterType"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index a12329c16..33c7c927a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); - if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - { + //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index b47506d6f..a79ef7ab7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); - if (scaleValueDefinition.Alias.Count > 0) - { + //if (scaleValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - if (scaleValueDefinition.Definition.Count > 0) - { + //if (scaleValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.HyperLink.Count > 0) - { + //if (scaleValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -132,8 +136,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); - if (scaleValueDefinition.Alias.Count > 0) - { + //if (scaleValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -142,13 +146,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - if (scaleValueDefinition.Definition.Count > 0) - { + //if (scaleValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedDomain.Count > 0) - { + //if (scaleValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedPerson.Count > 0) - { + //if (scaleValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.HyperLink.Count > 0) - { + //if (scaleValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -196,7 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -214,8 +218,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); - if (scaleValueDefinition.Alias.Count > 0) - { + //if (scaleValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -224,13 +228,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - if (scaleValueDefinition.Definition.Count > 0) - { + //if (scaleValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -239,11 +243,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedDomain.Count > 0) - { + //if (scaleValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedPerson.Count > 0) - { + //if (scaleValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.HyperLink.Count > 0) - { + //if (scaleValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -278,7 +282,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -308,8 +312,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (scaleValueDefinition.Alias.Count > 0) - { + //if (scaleValueDefinition.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) @@ -318,13 +322,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); - if (scaleValueDefinition.Definition.Count > 0) - { + //if (scaleValueDefinition.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) @@ -333,11 +337,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedDomain.Count > 0) - { + //if (scaleValueDefinition.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -346,11 +350,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.ExcludedPerson.Count > 0) - { + //if (scaleValueDefinition.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -359,11 +363,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (scaleValueDefinition.HyperLink.Count > 0) - { + //if (scaleValueDefinition.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -372,7 +376,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -434,6 +438,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -469,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -486,6 +500,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -503,6 +522,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -520,6 +544,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index b9ac65c0f..1534d61cf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); - if (section.Category.Count > 0) - { + //if (section.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (section.ExcludedDomain.Count > 0) - { + //if (section.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (section.ExcludedPerson.Count > 0) - { + //if (section.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -129,8 +133,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - if (section.Page.Count > 0) - { + //if (section.Page.Count > 0) + //{ writer.WriteStartArray("page"u8); foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) @@ -139,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -149,8 +153,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); - if (section.Category.Count > 0) - { + //if (section.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) @@ -159,15 +163,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (section.ExcludedDomain.Count > 0) - { + //if (section.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (section.ExcludedPerson.Count > 0) - { + //if (section.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -189,7 +193,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -200,8 +204,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - if (section.Page.Count > 0) - { + //if (section.Page.Count > 0) + //{ writer.WriteStartArray("page"u8); foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) @@ -210,7 +214,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -232,8 +236,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (section.Category.Count > 0) - { + //if (section.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) @@ -242,15 +246,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (section.ExcludedDomain.Count > 0) - { + //if (section.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -259,11 +263,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (section.ExcludedPerson.Count > 0) - { + //if (section.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -272,7 +276,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -283,8 +287,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); - if (section.Page.Count > 0) - { + //if (section.Page.Count > 0) + //{ writer.WriteStartArray("page"u8); foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) @@ -293,7 +297,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -347,6 +351,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -400,6 +409,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -417,6 +431,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -506,6 +525,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPage && objectListPage.Any()) { writer.WriteStartArray("page"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index 7508e4390..18eef5fce 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - if (sharedStyle.ExcludedDomain.Count > 0) - { + //if (sharedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sharedStyle.ExcludedPerson.Count > 0) - { + //if (sharedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -236,8 +240,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (sharedStyle.UsedColor.Count > 0) - { + //if (sharedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -246,7 +250,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -254,8 +258,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - if (sharedStyle.ExcludedDomain.Count > 0) - { + //if (sharedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -264,11 +268,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sharedStyle.ExcludedPerson.Count > 0) - { + //if (sharedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -277,7 +281,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -413,8 +417,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); - if (sharedStyle.UsedColor.Count > 0) - { + //if (sharedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -423,7 +427,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -442,8 +446,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); - if (sharedStyle.ExcludedDomain.Count > 0) - { + //if (sharedStyle.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -452,11 +456,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (sharedStyle.ExcludedPerson.Count > 0) - { + //if (sharedStyle.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -465,7 +469,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("fillColor"u8); @@ -601,8 +605,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); - if (sharedStyle.UsedColor.Count > 0) - { + //if (sharedStyle.UsedColor.Count > 0) + //{ writer.WriteStartArray("usedColor"u8); foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) @@ -611,7 +615,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -677,6 +681,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -694,6 +703,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1017,6 +1031,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) { writer.WriteStartArray("usedColor"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 8356dd5f9..b83b4153c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -103,8 +107,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - if (simpleParameterValue.ExcludedDomain.Count > 0) - { + //if (simpleParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -113,11 +117,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleParameterValue.ExcludedPerson.Count > 0) - { + //if (simpleParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -126,7 +130,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -154,8 +158,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - if (simpleParameterValue.ExcludedDomain.Count > 0) - { + //if (simpleParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -164,11 +168,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleParameterValue.ExcludedPerson.Count > 0) - { + //if (simpleParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -177,7 +181,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -218,8 +222,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); - if (simpleParameterValue.ExcludedDomain.Count > 0) - { + //if (simpleParameterValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -228,11 +232,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleParameterValue.ExcludedPerson.Count > 0) - { + //if (simpleParameterValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -241,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -329,6 +333,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -346,6 +355,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index fe28344e4..2749fa947 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); - if (simpleQuantityKind.Alias.Count > 0) - { + //if (simpleQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.Category.Count > 0) - { + //if (simpleQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,15 +105,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - if (simpleQuantityKind.Definition.Count > 0) - { + //if (simpleQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,11 +122,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.HyperLink.Count > 0) - { + //if (simpleQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -131,7 +135,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - if (simpleQuantityKind.PossibleScale.Count > 0) - { + //if (simpleQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -164,8 +168,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); - if (simpleQuantityKind.Alias.Count > 0) - { + //if (simpleQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -174,11 +178,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.Category.Count > 0) - { + //if (simpleQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -187,15 +191,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - if (simpleQuantityKind.Definition.Count > 0) - { + //if (simpleQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -204,11 +208,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedDomain.Count > 0) - { + //if (simpleQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedPerson.Count > 0) - { + //if (simpleQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -230,11 +234,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.HyperLink.Count > 0) - { + //if (simpleQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -243,7 +247,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -254,8 +258,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - if (simpleQuantityKind.PossibleScale.Count > 0) - { + //if (simpleQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -264,7 +268,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -278,8 +282,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); - if (simpleQuantityKind.Alias.Count > 0) - { + //if (simpleQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -288,11 +292,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.Category.Count > 0) - { + //if (simpleQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -301,15 +305,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - if (simpleQuantityKind.Definition.Count > 0) - { + //if (simpleQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -318,11 +322,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedDomain.Count > 0) - { + //if (simpleQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -331,11 +335,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedPerson.Count > 0) - { + //if (simpleQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -344,11 +348,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.HyperLink.Count > 0) - { + //if (simpleQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -357,7 +361,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -368,8 +372,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - if (simpleQuantityKind.PossibleScale.Count > 0) - { + //if (simpleQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -378,7 +382,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -404,8 +408,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (simpleQuantityKind.Alias.Count > 0) - { + //if (simpleQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -414,11 +418,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.Category.Count > 0) - { + //if (simpleQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -427,15 +431,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); - if (simpleQuantityKind.Definition.Count > 0) - { + //if (simpleQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -444,11 +448,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedDomain.Count > 0) - { + //if (simpleQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -457,11 +461,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.ExcludedPerson.Count > 0) - { + //if (simpleQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -470,11 +474,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleQuantityKind.HyperLink.Count > 0) - { + //if (simpleQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -483,7 +487,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -494,8 +498,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); - if (simpleQuantityKind.PossibleScale.Count > 0) - { + //if (simpleQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -504,7 +508,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -562,6 +566,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -579,6 +588,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -632,6 +646,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -649,6 +668,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -666,6 +690,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -683,6 +712,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -772,6 +806,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { writer.WriteStartArray("possibleScale"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index f37df4cd9..437deccc4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); - if (simpleUnit.Alias.Count > 0) - { + //if (simpleUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - if (simpleUnit.Definition.Count > 0) - { + //if (simpleUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.HyperLink.Count > 0) - { + //if (simpleUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -132,8 +136,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); - if (simpleUnit.Alias.Count > 0) - { + //if (simpleUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -142,13 +146,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - if (simpleUnit.Definition.Count > 0) - { + //if (simpleUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedDomain.Count > 0) - { + //if (simpleUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedPerson.Count > 0) - { + //if (simpleUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.HyperLink.Count > 0) - { + //if (simpleUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -196,7 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -214,8 +218,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); - if (simpleUnit.Alias.Count > 0) - { + //if (simpleUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -224,13 +228,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - if (simpleUnit.Definition.Count > 0) - { + //if (simpleUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -239,11 +243,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedDomain.Count > 0) - { + //if (simpleUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedPerson.Count > 0) - { + //if (simpleUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.HyperLink.Count > 0) - { + //if (simpleUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -278,7 +282,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -308,8 +312,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (simpleUnit.Alias.Count > 0) - { + //if (simpleUnit.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) @@ -318,13 +322,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); - if (simpleUnit.Definition.Count > 0) - { + //if (simpleUnit.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) @@ -333,11 +337,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedDomain.Count > 0) - { + //if (simpleUnit.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -346,11 +350,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.ExcludedPerson.Count > 0) - { + //if (simpleUnit.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -359,11 +363,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (simpleUnit.HyperLink.Count > 0) - { + //if (simpleUnit.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -372,7 +376,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -434,6 +438,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -469,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -486,6 +500,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -503,6 +522,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -520,6 +544,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 511776d45..a06e1d759 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataAnnotation.Discussion.Count > 0) - { + //if (siteDirectoryDataAnnotation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -96,11 +100,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -109,11 +113,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -122,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -133,8 +137,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - { + //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -143,7 +147,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -159,8 +163,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataAnnotation.Discussion.Count > 0) - { + //if (siteDirectoryDataAnnotation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -169,11 +173,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -182,11 +186,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -195,7 +199,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -206,8 +210,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - { + //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -216,7 +220,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -245,8 +249,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataAnnotation.Discussion.Count > 0) - { + //if (siteDirectoryDataAnnotation.Discussion.Count > 0) + //{ writer.WriteStartArray("discussion"u8); foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) @@ -255,11 +259,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -268,11 +272,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -281,7 +285,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -292,8 +296,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); - if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - { + //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) + //{ writer.WriteStartArray("relatedThing"u8); foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) @@ -302,7 +306,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -426,6 +430,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) { writer.WriteStartArray("discussion"u8); @@ -443,6 +452,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -460,6 +474,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -549,6 +568,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) { writer.WriteStartArray("relatedThing"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index 0b7294218..a94857204 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -96,11 +100,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -109,7 +113,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -152,11 +156,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -165,7 +169,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -211,8 +215,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -221,11 +225,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - { + //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -234,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -375,6 +379,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -392,6 +401,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 8c9fb8430..331b274e0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -103,8 +107,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteDirectory.Domain.Count > 0) - { + //if (siteDirectory.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) @@ -113,11 +117,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.DomainGroup.Count > 0) - { + //if (siteDirectory.DomainGroup.Count > 0) + //{ writer.WriteStartArray("domainGroup"u8); foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) @@ -126,15 +130,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectory.LogEntry.Count > 0) - { + //if (siteDirectory.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -143,11 +147,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Model.Count > 0) - { + //if (siteDirectory.Model.Count > 0) + //{ writer.WriteStartArray("model"u8); foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) @@ -156,13 +160,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - if (siteDirectory.NaturalLanguage.Count > 0) - { + //if (siteDirectory.NaturalLanguage.Count > 0) + //{ writer.WriteStartArray("naturalLanguage"u8); foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) @@ -171,11 +175,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Organization.Count > 0) - { + //if (siteDirectory.Organization.Count > 0) + //{ writer.WriteStartArray("organization"u8); foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) @@ -184,11 +188,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ParticipantRole.Count > 0) - { + //if (siteDirectory.ParticipantRole.Count > 0) + //{ writer.WriteStartArray("participantRole"u8); foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) @@ -197,11 +201,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Person.Count > 0) - { + //if (siteDirectory.Person.Count > 0) + //{ writer.WriteStartArray("person"u8); foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) @@ -210,11 +214,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.PersonRole.Count > 0) - { + //if (siteDirectory.PersonRole.Count > 0) + //{ writer.WriteStartArray("personRole"u8); foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) @@ -223,15 +227,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - { + //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) + //{ writer.WriteStartArray("siteReferenceDataLibrary"u8); foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) @@ -240,14 +244,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); - if (siteDirectory.Annotation.Count > 0) - { + //if (siteDirectory.Annotation.Count > 0) + //{ writer.WriteStartArray("annotation"u8); foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) @@ -256,7 +260,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -284,8 +288,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteDirectory.Domain.Count > 0) - { + //if (siteDirectory.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) @@ -294,11 +298,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.DomainGroup.Count > 0) - { + //if (siteDirectory.DomainGroup.Count > 0) + //{ writer.WriteStartArray("domainGroup"u8); foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) @@ -307,11 +311,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedDomain.Count > 0) - { + //if (siteDirectory.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -320,11 +324,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedPerson.Count > 0) - { + //if (siteDirectory.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -333,15 +337,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectory.LogEntry.Count > 0) - { + //if (siteDirectory.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -350,11 +354,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Model.Count > 0) - { + //if (siteDirectory.Model.Count > 0) + //{ writer.WriteStartArray("model"u8); foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) @@ -363,15 +367,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - if (siteDirectory.NaturalLanguage.Count > 0) - { + //if (siteDirectory.NaturalLanguage.Count > 0) + //{ writer.WriteStartArray("naturalLanguage"u8); foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) @@ -380,11 +384,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Organization.Count > 0) - { + //if (siteDirectory.Organization.Count > 0) + //{ writer.WriteStartArray("organization"u8); foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) @@ -393,11 +397,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ParticipantRole.Count > 0) - { + //if (siteDirectory.ParticipantRole.Count > 0) + //{ writer.WriteStartArray("participantRole"u8); foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) @@ -406,11 +410,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Person.Count > 0) - { + //if (siteDirectory.Person.Count > 0) + //{ writer.WriteStartArray("person"u8); foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) @@ -419,11 +423,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.PersonRole.Count > 0) - { + //if (siteDirectory.PersonRole.Count > 0) + //{ writer.WriteStartArray("personRole"u8); foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) @@ -432,15 +436,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - { + //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) + //{ writer.WriteStartArray("siteReferenceDataLibrary"u8); foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) @@ -449,14 +453,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); - if (siteDirectory.Annotation.Count > 0) - { + //if (siteDirectory.Annotation.Count > 0) + //{ writer.WriteStartArray("annotation"u8); foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) @@ -465,7 +469,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -493,8 +497,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteDirectory.Domain.Count > 0) - { + //if (siteDirectory.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) @@ -503,11 +507,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.DomainGroup.Count > 0) - { + //if (siteDirectory.DomainGroup.Count > 0) + //{ writer.WriteStartArray("domainGroup"u8); foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) @@ -516,11 +520,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedDomain.Count > 0) - { + //if (siteDirectory.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -529,11 +533,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedPerson.Count > 0) - { + //if (siteDirectory.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -542,15 +546,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectory.LogEntry.Count > 0) - { + //if (siteDirectory.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -559,11 +563,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Model.Count > 0) - { + //if (siteDirectory.Model.Count > 0) + //{ writer.WriteStartArray("model"u8); foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) @@ -572,15 +576,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - if (siteDirectory.NaturalLanguage.Count > 0) - { + //if (siteDirectory.NaturalLanguage.Count > 0) + //{ writer.WriteStartArray("naturalLanguage"u8); foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) @@ -589,11 +593,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Organization.Count > 0) - { + //if (siteDirectory.Organization.Count > 0) + //{ writer.WriteStartArray("organization"u8); foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) @@ -602,11 +606,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ParticipantRole.Count > 0) - { + //if (siteDirectory.ParticipantRole.Count > 0) + //{ writer.WriteStartArray("participantRole"u8); foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) @@ -615,11 +619,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Person.Count > 0) - { + //if (siteDirectory.Person.Count > 0) + //{ writer.WriteStartArray("person"u8); foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) @@ -628,11 +632,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.PersonRole.Count > 0) - { + //if (siteDirectory.PersonRole.Count > 0) + //{ writer.WriteStartArray("personRole"u8); foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) @@ -641,15 +645,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - { + //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) + //{ writer.WriteStartArray("siteReferenceDataLibrary"u8); foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) @@ -658,7 +662,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); @@ -676,8 +680,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteDirectory.Annotation.Count > 0) - { + //if (siteDirectory.Annotation.Count > 0) + //{ writer.WriteStartArray("annotation"u8); foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) @@ -686,7 +690,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -714,8 +718,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteDirectory.Domain.Count > 0) - { + //if (siteDirectory.Domain.Count > 0) + //{ writer.WriteStartArray("domain"u8); foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) @@ -724,11 +728,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.DomainGroup.Count > 0) - { + //if (siteDirectory.DomainGroup.Count > 0) + //{ writer.WriteStartArray("domainGroup"u8); foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) @@ -737,11 +741,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedDomain.Count > 0) - { + //if (siteDirectory.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -750,11 +754,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ExcludedPerson.Count > 0) - { + //if (siteDirectory.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -763,15 +767,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteDirectory.LogEntry.Count > 0) - { + //if (siteDirectory.LogEntry.Count > 0) + //{ writer.WriteStartArray("logEntry"u8); foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) @@ -780,11 +784,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Model.Count > 0) - { + //if (siteDirectory.Model.Count > 0) + //{ writer.WriteStartArray("model"u8); foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) @@ -793,15 +797,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); - if (siteDirectory.NaturalLanguage.Count > 0) - { + //if (siteDirectory.NaturalLanguage.Count > 0) + //{ writer.WriteStartArray("naturalLanguage"u8); foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) @@ -810,11 +814,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Organization.Count > 0) - { + //if (siteDirectory.Organization.Count > 0) + //{ writer.WriteStartArray("organization"u8); foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) @@ -823,11 +827,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.ParticipantRole.Count > 0) - { + //if (siteDirectory.ParticipantRole.Count > 0) + //{ writer.WriteStartArray("participantRole"u8); foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) @@ -836,11 +840,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.Person.Count > 0) - { + //if (siteDirectory.Person.Count > 0) + //{ writer.WriteStartArray("person"u8); foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) @@ -849,11 +853,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectory.PersonRole.Count > 0) - { + //if (siteDirectory.PersonRole.Count > 0) + //{ writer.WriteStartArray("personRole"u8); foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) @@ -862,15 +866,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); - if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - { + //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) + //{ writer.WriteStartArray("siteReferenceDataLibrary"u8); foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) @@ -879,7 +883,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); @@ -929,6 +933,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAnnotation && objectListAnnotation.Any()) { writer.WriteStartArray("annotation"u8); @@ -1018,6 +1027,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomain && objectListDomain.Any()) { writer.WriteStartArray("domain"u8); @@ -1035,6 +1049,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDomainGroup && objectListDomainGroup.Any()) { writer.WriteStartArray("domainGroup"u8); @@ -1052,6 +1071,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -1069,6 +1093,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1122,6 +1151,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) { writer.WriteStartArray("logEntry"u8); @@ -1139,6 +1173,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListModel && objectListModel.Any()) { writer.WriteStartArray("model"u8); @@ -1192,6 +1231,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListNaturalLanguage && objectListNaturalLanguage.Any()) { writer.WriteStartArray("naturalLanguage"u8); @@ -1209,6 +1253,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListOrganization && objectListOrganization.Any()) { writer.WriteStartArray("organization"u8); @@ -1226,6 +1275,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParticipantRole && objectListParticipantRole.Any()) { writer.WriteStartArray("participantRole"u8); @@ -1243,6 +1297,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPerson && objectListPerson.Any()) { writer.WriteStartArray("person"u8); @@ -1260,6 +1319,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPersonRole && objectListPersonRole.Any()) { writer.WriteStartArray("personRole"u8); @@ -1313,6 +1377,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSiteReferenceDataLibrary && objectListSiteReferenceDataLibrary.Any()) { writer.WriteStartArray("siteReferenceDataLibrary"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 8e0f9b2c1..777a9d191 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -121,8 +125,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -131,11 +135,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -144,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -175,8 +179,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); - if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - { + //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -198,7 +202,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -276,6 +280,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -293,6 +302,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 0a97b3316..c7db63bac 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); - if (siteLogEntry.AffectedDomainIid.Count > 0) - { + //if (siteLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.AffectedItemIid.Count > 0) - { + //if (siteLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) @@ -101,7 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -114,8 +118,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteLogEntry.Category.Count > 0) - { + //if (siteLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -124,7 +128,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -144,8 +148,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); - if (siteLogEntry.AffectedDomainIid.Count > 0) - { + //if (siteLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) @@ -154,11 +158,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.AffectedItemIid.Count > 0) - { + //if (siteLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) @@ -167,7 +171,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -180,8 +184,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteLogEntry.Category.Count > 0) - { + //if (siteLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -190,7 +194,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -199,8 +203,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteLogEntry.ExcludedDomain.Count > 0) - { + //if (siteLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.ExcludedPerson.Count > 0) - { + //if (siteLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -222,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -238,8 +242,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); - if (siteLogEntry.AffectedDomainIid.Count > 0) - { + //if (siteLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.AffectedItemIid.Count > 0) - { + //if (siteLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -274,8 +278,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteLogEntry.Category.Count > 0) - { + //if (siteLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -293,8 +297,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteLogEntry.ExcludedDomain.Count > 0) - { + //if (siteLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -303,11 +307,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.ExcludedPerson.Count > 0) - { + //if (siteLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -316,7 +320,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -325,8 +329,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); - if (siteLogEntry.LogEntryChangelogItem.Count > 0) - { + //if (siteLogEntry.LogEntryChangelogItem.Count > 0) + //{ writer.WriteStartArray("logEntryChangelogItem"u8); foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) @@ -335,7 +339,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -357,8 +361,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteLogEntry.AffectedDomainIid.Count > 0) - { + //if (siteLogEntry.AffectedDomainIid.Count > 0) + //{ writer.WriteStartArray("affectedDomainIid"u8); foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) @@ -367,11 +371,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.AffectedItemIid.Count > 0) - { + //if (siteLogEntry.AffectedItemIid.Count > 0) + //{ writer.WriteStartArray("affectedItemIid"u8); foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) @@ -380,7 +384,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("author"u8); @@ -393,8 +397,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteLogEntry.Category.Count > 0) - { + //if (siteLogEntry.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) @@ -403,7 +407,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -412,8 +416,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (siteLogEntry.ExcludedDomain.Count > 0) - { + //if (siteLogEntry.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -422,11 +426,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteLogEntry.ExcludedPerson.Count > 0) - { + //if (siteLogEntry.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -435,7 +439,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -444,8 +448,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); - if (siteLogEntry.LogEntryChangelogItem.Count > 0) - { + //if (siteLogEntry.LogEntryChangelogItem.Count > 0) + //{ writer.WriteStartArray("logEntryChangelogItem"u8); foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) @@ -454,7 +458,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -508,6 +512,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) { writer.WriteStartArray("affectedDomainIid"u8); @@ -525,6 +534,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) { writer.WriteStartArray("affectedItemIid"u8); @@ -560,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -631,6 +650,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -648,6 +672,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -719,6 +748,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) { writer.WriteStartArray("logEntryChangelogItem"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index 96d5f3ffc..f5c1c634b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); - if (siteReferenceDataLibrary.Alias.Count > 0) - { + //if (siteReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -101,11 +105,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (siteReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -114,13 +118,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - if (siteReferenceDataLibrary.Constant.Count > 0) - { + //if (siteReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Definition.Count > 0) - { + //if (siteReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.FileType.Count > 0) - { + //if (siteReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -168,11 +172,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Glossary.Count > 0) - { + //if (siteReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.HyperLink.Count > 0) - { + //if (siteReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -194,7 +198,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -203,8 +207,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - if (siteReferenceDataLibrary.ParameterType.Count > 0) - { + //if (siteReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -213,11 +217,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -226,7 +230,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -242,8 +246,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - if (siteReferenceDataLibrary.Rule.Count > 0) - { + //if (siteReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Scale.Count > 0) - { + //if (siteReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -265,13 +269,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - if (siteReferenceDataLibrary.Unit.Count > 0) - { + //if (siteReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -280,11 +284,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -293,14 +297,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); - if (siteReferenceDataLibrary.Alias.Count > 0) - { + //if (siteReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -309,11 +313,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -322,11 +326,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (siteReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -335,13 +339,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - if (siteReferenceDataLibrary.Constant.Count > 0) - { + //if (siteReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -350,11 +354,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Definition.Count > 0) - { + //if (siteReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -376,11 +380,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -389,11 +393,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -402,11 +406,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.FileType.Count > 0) - { + //if (siteReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -415,11 +419,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Glossary.Count > 0) - { + //if (siteReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -428,11 +432,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.HyperLink.Count > 0) - { + //if (siteReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -441,7 +445,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -452,8 +456,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - if (siteReferenceDataLibrary.ParameterType.Count > 0) - { + //if (siteReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -462,11 +466,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -475,7 +479,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -491,8 +495,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - if (siteReferenceDataLibrary.Rule.Count > 0) - { + //if (siteReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -501,11 +505,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Scale.Count > 0) - { + //if (siteReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -514,13 +518,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); - if (siteReferenceDataLibrary.Unit.Count > 0) - { + //if (siteReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -529,11 +533,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -542,14 +546,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); - if (siteReferenceDataLibrary.Alias.Count > 0) - { + //if (siteReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -558,11 +562,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -571,11 +575,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (siteReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -584,13 +588,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - if (siteReferenceDataLibrary.Constant.Count > 0) - { + //if (siteReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -599,11 +603,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -612,11 +616,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Definition.Count > 0) - { + //if (siteReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -625,11 +629,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -638,11 +642,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -651,11 +655,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.FileType.Count > 0) - { + //if (siteReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -664,11 +668,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Glossary.Count > 0) - { + //if (siteReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -677,11 +681,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.HyperLink.Count > 0) - { + //if (siteReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -690,7 +694,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -701,8 +705,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - if (siteReferenceDataLibrary.ParameterType.Count > 0) - { + //if (siteReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -711,11 +715,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -724,7 +728,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -740,8 +744,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - if (siteReferenceDataLibrary.Rule.Count > 0) - { + //if (siteReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -750,11 +754,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Scale.Count > 0) - { + //if (siteReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -763,15 +767,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); - if (siteReferenceDataLibrary.Unit.Count > 0) - { + //if (siteReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -780,11 +784,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -793,7 +797,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -809,8 +813,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (siteReferenceDataLibrary.Alias.Count > 0) - { + //if (siteReferenceDataLibrary.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) @@ -819,11 +823,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - { + //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) + //{ writer.WriteStartArray("baseQuantityKind"u8); foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) @@ -832,11 +836,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.BaseUnit.Count > 0) - { + //if (siteReferenceDataLibrary.BaseUnit.Count > 0) + //{ writer.WriteStartArray("baseUnit"u8); foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) @@ -845,13 +849,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); - if (siteReferenceDataLibrary.Constant.Count > 0) - { + //if (siteReferenceDataLibrary.Constant.Count > 0) + //{ writer.WriteStartArray("constant"u8); foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) @@ -860,11 +864,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - { + //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) + //{ writer.WriteStartArray("definedCategory"u8); foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) @@ -873,11 +877,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Definition.Count > 0) - { + //if (siteReferenceDataLibrary.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) @@ -886,11 +890,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -899,11 +903,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - { + //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -912,11 +916,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.FileType.Count > 0) - { + //if (siteReferenceDataLibrary.FileType.Count > 0) + //{ writer.WriteStartArray("fileType"u8); foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) @@ -925,11 +929,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Glossary.Count > 0) - { + //if (siteReferenceDataLibrary.Glossary.Count > 0) + //{ writer.WriteStartArray("glossary"u8); foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) @@ -938,11 +942,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.HyperLink.Count > 0) - { + //if (siteReferenceDataLibrary.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -951,7 +955,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -962,8 +966,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); - if (siteReferenceDataLibrary.ParameterType.Count > 0) - { + //if (siteReferenceDataLibrary.ParameterType.Count > 0) + //{ writer.WriteStartArray("parameterType"u8); foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) @@ -972,11 +976,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - { + //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) + //{ writer.WriteStartArray("referenceSource"u8); foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) @@ -985,7 +989,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("requiredRdl"u8); @@ -1001,8 +1005,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); - if (siteReferenceDataLibrary.Rule.Count > 0) - { + //if (siteReferenceDataLibrary.Rule.Count > 0) + //{ writer.WriteStartArray("rule"u8); foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) @@ -1011,11 +1015,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.Scale.Count > 0) - { + //if (siteReferenceDataLibrary.Scale.Count > 0) + //{ writer.WriteStartArray("scale"u8); foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) @@ -1024,15 +1028,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); - if (siteReferenceDataLibrary.Unit.Count > 0) - { + //if (siteReferenceDataLibrary.Unit.Count > 0) + //{ writer.WriteStartArray("unit"u8); foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) @@ -1041,11 +1045,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - { + //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) + //{ writer.WriteStartArray("unitPrefix"u8); foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) @@ -1054,7 +1058,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -1102,6 +1106,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -1119,6 +1128,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) { writer.WriteStartArray("baseQuantityKind"u8); @@ -1136,6 +1150,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) { writer.WriteStartArray("baseUnit"u8); @@ -1171,6 +1190,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListConstant && objectListConstant.Any()) { writer.WriteStartArray("constant"u8); @@ -1188,6 +1212,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) { writer.WriteStartArray("definedCategory"u8); @@ -1205,6 +1234,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -1222,6 +1256,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -1239,6 +1278,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -1256,6 +1300,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListFileType && objectListFileType.Any()) { writer.WriteStartArray("fileType"u8); @@ -1273,6 +1322,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) { writer.WriteStartArray("glossary"u8); @@ -1290,6 +1344,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -1379,6 +1438,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) { writer.WriteStartArray("parameterType"u8); @@ -1396,6 +1460,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) { writer.WriteStartArray("referenceSource"u8); @@ -1449,6 +1518,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRule && objectListRule.Any()) { writer.WriteStartArray("rule"u8); @@ -1466,6 +1540,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListScale && objectListScale.Any()) { writer.WriteStartArray("scale"u8); @@ -1519,6 +1598,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUnit && objectListUnit.Any()) { writer.WriteStartArray("unit"u8); @@ -1536,6 +1620,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) { writer.WriteStartArray("unitPrefix"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 89a3d3817..399e1e782 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (solution.ExcludedDomain.Count > 0) - { + //if (solution.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -96,11 +100,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (solution.ExcludedPerson.Count > 0) - { + //if (solution.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -109,7 +113,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -133,8 +137,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (solution.ExcludedDomain.Count > 0) - { + //if (solution.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -143,11 +147,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (solution.ExcludedPerson.Count > 0) - { + //if (solution.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -156,7 +160,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -193,8 +197,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (solution.ExcludedDomain.Count > 0) - { + //if (solution.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -203,11 +207,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (solution.ExcludedPerson.Count > 0) - { + //if (solution.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -216,7 +220,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -348,6 +352,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -365,6 +374,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index 893c7dc2b..f25bf5694 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); - if (specializedQuantityKind.Alias.Count > 0) - { + //if (specializedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.Category.Count > 0) - { + //if (specializedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,15 +105,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - if (specializedQuantityKind.Definition.Count > 0) - { + //if (specializedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -118,13 +122,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - if (specializedQuantityKind.HyperLink.Count > 0) - { + //if (specializedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -133,7 +137,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -142,8 +146,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - if (specializedQuantityKind.PossibleScale.Count > 0) - { + //if (specializedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -152,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -166,8 +170,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); - if (specializedQuantityKind.Alias.Count > 0) - { + //if (specializedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -176,11 +180,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.Category.Count > 0) - { + //if (specializedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -189,15 +193,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - if (specializedQuantityKind.Definition.Count > 0) - { + //if (specializedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -206,11 +210,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedDomain.Count > 0) - { + //if (specializedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -219,11 +223,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedPerson.Count > 0) - { + //if (specializedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -232,13 +236,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - if (specializedQuantityKind.HyperLink.Count > 0) - { + //if (specializedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -258,8 +262,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - if (specializedQuantityKind.PossibleScale.Count > 0) - { + //if (specializedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -268,7 +272,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -282,8 +286,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); - if (specializedQuantityKind.Alias.Count > 0) - { + //if (specializedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -292,11 +296,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.Category.Count > 0) - { + //if (specializedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -305,15 +309,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - if (specializedQuantityKind.Definition.Count > 0) - { + //if (specializedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -322,11 +326,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedDomain.Count > 0) - { + //if (specializedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -335,11 +339,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedPerson.Count > 0) - { + //if (specializedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -348,13 +352,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - if (specializedQuantityKind.HyperLink.Count > 0) - { + //if (specializedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -363,7 +367,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -374,8 +378,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - if (specializedQuantityKind.PossibleScale.Count > 0) - { + //if (specializedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -384,7 +388,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -410,8 +414,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (specializedQuantityKind.Alias.Count > 0) - { + //if (specializedQuantityKind.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) @@ -420,11 +424,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.Category.Count > 0) - { + //if (specializedQuantityKind.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) @@ -433,15 +437,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); - if (specializedQuantityKind.Definition.Count > 0) - { + //if (specializedQuantityKind.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) @@ -450,11 +454,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedDomain.Count > 0) - { + //if (specializedQuantityKind.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -463,11 +467,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (specializedQuantityKind.ExcludedPerson.Count > 0) - { + //if (specializedQuantityKind.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -476,13 +480,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); - if (specializedQuantityKind.HyperLink.Count > 0) - { + //if (specializedQuantityKind.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -491,7 +495,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -502,8 +506,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); - if (specializedQuantityKind.PossibleScale.Count > 0) - { + //if (specializedQuantityKind.PossibleScale.Count > 0) + //{ writer.WriteStartArray("possibleScale"u8); foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) @@ -512,7 +516,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -570,6 +574,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -587,6 +596,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -640,6 +654,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -657,6 +676,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -674,6 +698,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -709,6 +738,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -798,6 +832,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) { writer.WriteStartArray("possibleScale"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 3cf7db465..5a61ed4f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); - if (stakeHolderValueMap.Alias.Count > 0) - { + //if (stakeHolderValueMap.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Category.Count > 0) - { + //if (stakeHolderValueMap.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - if (stakeHolderValueMap.Definition.Count > 0) - { + //if (stakeHolderValueMap.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Goal.Count > 0) - { + //if (stakeHolderValueMap.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) @@ -155,11 +159,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.HyperLink.Count > 0) - { + //if (stakeHolderValueMap.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -168,7 +172,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -177,8 +181,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - if (stakeHolderValueMap.Requirement.Count > 0) - { + //if (stakeHolderValueMap.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -187,13 +191,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - if (stakeHolderValueMap.Settings.Count > 0) - { + //if (stakeHolderValueMap.Settings.Count > 0) + //{ writer.WriteStartArray("settings"u8); foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) @@ -202,13 +206,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - if (stakeHolderValueMap.StakeholderValue.Count > 0) - { + //if (stakeHolderValueMap.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -217,11 +221,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ValueGroup.Count > 0) - { + //if (stakeHolderValueMap.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -230,14 +234,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); - if (stakeHolderValueMap.Alias.Count > 0) - { + //if (stakeHolderValueMap.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) @@ -246,11 +250,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Category.Count > 0) - { + //if (stakeHolderValueMap.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) @@ -259,13 +263,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - if (stakeHolderValueMap.Definition.Count > 0) - { + //if (stakeHolderValueMap.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) @@ -274,11 +278,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -287,11 +291,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -300,11 +304,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Goal.Count > 0) - { + //if (stakeHolderValueMap.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) @@ -313,11 +317,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.HyperLink.Count > 0) - { + //if (stakeHolderValueMap.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -326,7 +330,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -335,8 +339,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - if (stakeHolderValueMap.Requirement.Count > 0) - { + //if (stakeHolderValueMap.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -345,13 +349,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - if (stakeHolderValueMap.Settings.Count > 0) - { + //if (stakeHolderValueMap.Settings.Count > 0) + //{ writer.WriteStartArray("settings"u8); foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) @@ -360,13 +364,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - if (stakeHolderValueMap.StakeholderValue.Count > 0) - { + //if (stakeHolderValueMap.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -375,13 +379,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); - if (stakeHolderValueMap.ValueGroup.Count > 0) - { + //if (stakeHolderValueMap.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -390,7 +394,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -406,8 +410,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (stakeHolderValueMap.Alias.Count > 0) - { + //if (stakeHolderValueMap.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) @@ -416,11 +420,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Category.Count > 0) - { + //if (stakeHolderValueMap.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) @@ -429,13 +433,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); - if (stakeHolderValueMap.Definition.Count > 0) - { + //if (stakeHolderValueMap.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) @@ -444,11 +448,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMap.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -457,11 +461,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMap.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -470,11 +474,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.Goal.Count > 0) - { + //if (stakeHolderValueMap.Goal.Count > 0) + //{ writer.WriteStartArray("goal"u8); foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) @@ -483,11 +487,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMap.HyperLink.Count > 0) - { + //if (stakeHolderValueMap.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -496,7 +500,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -505,8 +509,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); - if (stakeHolderValueMap.Requirement.Count > 0) - { + //if (stakeHolderValueMap.Requirement.Count > 0) + //{ writer.WriteStartArray("requirement"u8); foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) @@ -515,13 +519,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); - if (stakeHolderValueMap.Settings.Count > 0) - { + //if (stakeHolderValueMap.Settings.Count > 0) + //{ writer.WriteStartArray("settings"u8); foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) @@ -530,13 +534,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); - if (stakeHolderValueMap.StakeholderValue.Count > 0) - { + //if (stakeHolderValueMap.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -545,13 +549,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); - if (stakeHolderValueMap.ValueGroup.Count > 0) - { + //if (stakeHolderValueMap.ValueGroup.Count > 0) + //{ writer.WriteStartArray("valueGroup"u8); foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) @@ -560,7 +564,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -608,6 +612,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -625,6 +634,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -660,6 +674,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -677,6 +696,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -694,6 +718,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -711,6 +740,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListGoal && objectListGoal.Any()) { writer.WriteStartArray("goal"u8); @@ -728,6 +762,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -799,6 +838,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) { writer.WriteStartArray("requirement"u8); @@ -834,6 +878,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListSettings && objectListSettings.Any()) { writer.WriteStartArray("settings"u8); @@ -869,6 +918,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { writer.WriteStartArray("stakeholderValue"u8); @@ -904,6 +958,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) { writer.WriteStartArray("valueGroup"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 83c0a93ab..1a1b43ab0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -80,8 +84,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -90,11 +94,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -103,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -150,8 +154,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -160,11 +164,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -173,7 +177,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -233,8 +237,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); - if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -243,11 +247,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - { + //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -256,7 +260,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("goalToValueGroupRelationship"u8); @@ -363,6 +367,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -380,6 +389,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 84976b8a5..31e94d63d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); - if (stakeholder.Alias.Count > 0) - { + //if (stakeholder.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.Category.Count > 0) - { + //if (stakeholder.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - if (stakeholder.Definition.Count > 0) - { + //if (stakeholder.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedDomain.Count > 0) - { + //if (stakeholder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedPerson.Count > 0) - { + //if (stakeholder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.HyperLink.Count > 0) - { + //if (stakeholder.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - if (stakeholder.StakeholderValue.Count > 0) - { + //if (stakeholder.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -178,14 +182,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); - if (stakeholder.Alias.Count > 0) - { + //if (stakeholder.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) @@ -194,11 +198,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.Category.Count > 0) - { + //if (stakeholder.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) @@ -207,13 +211,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - if (stakeholder.Definition.Count > 0) - { + //if (stakeholder.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedDomain.Count > 0) - { + //if (stakeholder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedPerson.Count > 0) - { + //if (stakeholder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -248,11 +252,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.HyperLink.Count > 0) - { + //if (stakeholder.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -261,7 +265,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -274,8 +278,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - if (stakeholder.StakeholderValue.Count > 0) - { + //if (stakeholder.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); @@ -302,8 +306,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (stakeholder.Alias.Count > 0) - { + //if (stakeholder.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) @@ -312,11 +316,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.Category.Count > 0) - { + //if (stakeholder.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) @@ -325,13 +329,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); - if (stakeholder.Definition.Count > 0) - { + //if (stakeholder.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedDomain.Count > 0) - { + //if (stakeholder.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -353,11 +357,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.ExcludedPerson.Count > 0) - { + //if (stakeholder.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -366,11 +370,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholder.HyperLink.Count > 0) - { + //if (stakeholder.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -379,7 +383,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -392,8 +396,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); - if (stakeholder.StakeholderValue.Count > 0) - { + //if (stakeholder.StakeholderValue.Count > 0) + //{ writer.WriteStartArray("stakeholderValue"u8); foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) @@ -402,7 +406,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); @@ -452,6 +456,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -469,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -504,6 +518,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -521,6 +540,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -538,6 +562,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -555,6 +584,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); @@ -662,6 +696,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) { writer.WriteStartArray("stakeholderValue"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 6382cf966..1df68567c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); - if (stakeholderValue.Alias.Count > 0) - { + //if (stakeholderValue.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.Category.Count > 0) - { + //if (stakeholderValue.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - if (stakeholderValue.Definition.Count > 0) - { + //if (stakeholderValue.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedDomain.Count > 0) - { + //if (stakeholderValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedPerson.Count > 0) - { + //if (stakeholderValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.HyperLink.Count > 0) - { + //if (stakeholderValue.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); - if (stakeholderValue.Alias.Count > 0) - { + //if (stakeholderValue.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.Category.Count > 0) - { + //if (stakeholderValue.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) @@ -194,13 +198,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - if (stakeholderValue.Definition.Count > 0) - { + //if (stakeholderValue.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedDomain.Count > 0) - { + //if (stakeholderValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedPerson.Count > 0) - { + //if (stakeholderValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.HyperLink.Count > 0) - { + //if (stakeholderValue.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -248,7 +252,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (stakeholderValue.Alias.Count > 0) - { + //if (stakeholderValue.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) @@ -286,11 +290,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.Category.Count > 0) - { + //if (stakeholderValue.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) @@ -299,13 +303,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); - if (stakeholderValue.Definition.Count > 0) - { + //if (stakeholderValue.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedDomain.Count > 0) - { + //if (stakeholderValue.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.ExcludedPerson.Count > 0) - { + //if (stakeholderValue.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (stakeholderValue.HyperLink.Count > 0) - { + //if (stakeholderValue.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -353,7 +357,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -413,6 +417,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -430,6 +439,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -465,6 +479,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -482,6 +501,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -499,6 +523,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -516,6 +545,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index 070a98147..56b32e3d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -86,8 +90,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - if (telephoneNumber.VcardType.Count > 0) - { + //if (telephoneNumber.VcardType.Count > 0) + //{ writer.WriteStartArray("vcardType"u8); foreach(var vcardTypeItem in telephoneNumber.VcardType) @@ -96,7 +100,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -104,8 +108,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - if (telephoneNumber.ExcludedDomain.Count > 0) - { + //if (telephoneNumber.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -114,11 +118,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (telephoneNumber.ExcludedPerson.Count > 0) - { + //if (telephoneNumber.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -127,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -138,8 +142,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - if (telephoneNumber.VcardType.Count > 0) - { + //if (telephoneNumber.VcardType.Count > 0) + //{ writer.WriteStartArray("vcardType"u8); foreach(var vcardTypeItem in telephoneNumber.VcardType) @@ -148,7 +152,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -156,8 +160,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - if (telephoneNumber.ExcludedDomain.Count > 0) - { + //if (telephoneNumber.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -166,11 +170,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (telephoneNumber.ExcludedPerson.Count > 0) - { + //if (telephoneNumber.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -179,7 +183,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -192,8 +196,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - if (telephoneNumber.VcardType.Count > 0) - { + //if (telephoneNumber.VcardType.Count > 0) + //{ writer.WriteStartArray("vcardType"u8); foreach(var vcardTypeItem in telephoneNumber.VcardType) @@ -202,7 +206,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -221,8 +225,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); - if (telephoneNumber.ExcludedDomain.Count > 0) - { + //if (telephoneNumber.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -231,11 +235,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (telephoneNumber.ExcludedPerson.Count > 0) - { + //if (telephoneNumber.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -244,7 +248,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -257,8 +261,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); - if (telephoneNumber.VcardType.Count > 0) - { + //if (telephoneNumber.VcardType.Count > 0) + //{ writer.WriteStartArray("vcardType"u8); foreach(var vcardTypeItem in telephoneNumber.VcardType) @@ -267,7 +271,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -333,6 +337,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -350,6 +359,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -457,6 +471,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListVcardType && objectListVcardType.Any()) { writer.WriteStartArray("vcardType"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index d48d6fe6f..0136bd424 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); - if (term.Alias.Count > 0) - { + //if (term.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,13 +92,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - if (term.Definition.Count > 0) - { + //if (term.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.HyperLink.Count > 0) - { + //if (term.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -132,8 +136,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); - if (term.Alias.Count > 0) - { + //if (term.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -142,13 +146,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - if (term.Definition.Count > 0) - { + //if (term.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedDomain.Count > 0) - { + //if (term.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -170,11 +174,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedPerson.Count > 0) - { + //if (term.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -183,11 +187,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.HyperLink.Count > 0) - { + //if (term.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -196,7 +200,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -214,8 +218,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); - if (term.Alias.Count > 0) - { + //if (term.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -224,13 +228,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - if (term.Definition.Count > 0) - { + //if (term.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) @@ -239,11 +243,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedDomain.Count > 0) - { + //if (term.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -252,11 +256,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedPerson.Count > 0) - { + //if (term.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -265,11 +269,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.HyperLink.Count > 0) - { + //if (term.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -278,7 +282,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -308,8 +312,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (term.Alias.Count > 0) - { + //if (term.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) @@ -318,13 +322,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); - if (term.Definition.Count > 0) - { + //if (term.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) @@ -333,11 +337,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedDomain.Count > 0) - { + //if (term.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -346,11 +350,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.ExcludedPerson.Count > 0) - { + //if (term.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -359,11 +363,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (term.HyperLink.Count > 0) - { + //if (term.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -372,7 +376,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -434,6 +438,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -469,6 +478,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -486,6 +500,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -503,6 +522,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -520,6 +544,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index ddb1be614..0970643b9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); - if (textParameterType.Alias.Count > 0) - { + //if (textParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.Category.Count > 0) - { + //if (textParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - if (textParameterType.Definition.Count > 0) - { + //if (textParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.HyperLink.Count > 0) - { + //if (textParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); - if (textParameterType.Alias.Count > 0) - { + //if (textParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.Category.Count > 0) - { + //if (textParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - if (textParameterType.Definition.Count > 0) - { + //if (textParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedDomain.Count > 0) - { + //if (textParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedPerson.Count > 0) - { + //if (textParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.HyperLink.Count > 0) - { + //if (textParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); - if (textParameterType.Alias.Count > 0) - { + //if (textParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.Category.Count > 0) - { + //if (textParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - if (textParameterType.Definition.Count > 0) - { + //if (textParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedDomain.Count > 0) - { + //if (textParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedPerson.Count > 0) - { + //if (textParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.HyperLink.Count > 0) - { + //if (textParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (textParameterType.Alias.Count > 0) - { + //if (textParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.Category.Count > 0) - { + //if (textParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); - if (textParameterType.Definition.Count > 0) - { + //if (textParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedDomain.Count > 0) - { + //if (textParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.ExcludedPerson.Count > 0) - { + //if (textParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textParameterType.HyperLink.Count > 0) - { + //if (textParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -430,7 +434,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -597,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index 70e59fd3e..79653cdc2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); - if (textualNote.Category.Count > 0) - { + //if (textualNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -88,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -97,8 +101,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (textualNote.ExcludedDomain.Count > 0) - { + //if (textualNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -107,11 +111,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textualNote.ExcludedPerson.Count > 0) - { + //if (textualNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -120,7 +124,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -140,8 +144,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); - if (textualNote.Category.Count > 0) - { + //if (textualNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -150,7 +154,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -159,8 +163,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (textualNote.ExcludedDomain.Count > 0) - { + //if (textualNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -169,11 +173,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textualNote.ExcludedPerson.Count > 0) - { + //if (textualNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -182,7 +186,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -214,8 +218,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (textualNote.Category.Count > 0) - { + //if (textualNote.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -233,8 +237,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); - if (textualNote.ExcludedDomain.Count > 0) - { + //if (textualNote.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -243,11 +247,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (textualNote.ExcludedPerson.Count > 0) - { + //if (textualNote.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -256,7 +260,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -320,6 +324,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -391,6 +400,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -408,6 +422,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index 3b7d7173d..c7c7b521e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); - if (timeOfDayParameterType.Alias.Count > 0) - { + //if (timeOfDayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.Category.Count > 0) - { + //if (timeOfDayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - if (timeOfDayParameterType.Definition.Count > 0) - { + //if (timeOfDayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.HyperLink.Count > 0) - { + //if (timeOfDayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -129,7 +133,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -147,8 +151,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); - if (timeOfDayParameterType.Alias.Count > 0) - { + //if (timeOfDayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -157,11 +161,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.Category.Count > 0) - { + //if (timeOfDayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -170,13 +174,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - if (timeOfDayParameterType.Definition.Count > 0) - { + //if (timeOfDayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -185,11 +189,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedDomain.Count > 0) - { + //if (timeOfDayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedPerson.Count > 0) - { + //if (timeOfDayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,11 +215,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.HyperLink.Count > 0) - { + //if (timeOfDayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -224,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -244,8 +248,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); - if (timeOfDayParameterType.Alias.Count > 0) - { + //if (timeOfDayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -254,11 +258,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.Category.Count > 0) - { + //if (timeOfDayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -267,13 +271,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - if (timeOfDayParameterType.Definition.Count > 0) - { + //if (timeOfDayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -282,11 +286,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedDomain.Count > 0) - { + //if (timeOfDayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -295,11 +299,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedPerson.Count > 0) - { + //if (timeOfDayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -308,11 +312,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.HyperLink.Count > 0) - { + //if (timeOfDayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -321,7 +325,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -353,8 +357,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (timeOfDayParameterType.Alias.Count > 0) - { + //if (timeOfDayParameterType.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) @@ -363,11 +367,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.Category.Count > 0) - { + //if (timeOfDayParameterType.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) @@ -376,13 +380,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); - if (timeOfDayParameterType.Definition.Count > 0) - { + //if (timeOfDayParameterType.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) @@ -391,11 +395,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedDomain.Count > 0) - { + //if (timeOfDayParameterType.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -404,11 +408,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.ExcludedPerson.Count > 0) - { + //if (timeOfDayParameterType.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -417,11 +421,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (timeOfDayParameterType.HyperLink.Count > 0) - { + //if (timeOfDayParameterType.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -430,7 +434,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -494,6 +498,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -511,6 +520,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -546,6 +560,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -563,6 +582,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -580,6 +604,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -597,6 +626,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 98f7e5eef..b0a8b580a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - if (unitFactor.ExcludedDomain.Count > 0) - { + //if (unitFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitFactor.ExcludedPerson.Count > 0) - { + //if (unitFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - if (unitFactor.ExcludedDomain.Count > 0) - { + //if (unitFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitFactor.ExcludedPerson.Count > 0) - { + //if (unitFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); - if (unitFactor.ExcludedDomain.Count > 0) - { + //if (unitFactor.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitFactor.ExcludedPerson.Count > 0) - { + //if (unitFactor.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 46c9932fa..62cf1e705 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); - if (unitPrefix.Alias.Count > 0) - { + //if (unitPrefix.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,15 +92,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - if (unitPrefix.Definition.Count > 0) - { + //if (unitPrefix.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) @@ -105,11 +109,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.HyperLink.Count > 0) - { + //if (unitPrefix.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -118,7 +122,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); - if (unitPrefix.Alias.Count > 0) - { + //if (unitPrefix.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) @@ -144,15 +148,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - if (unitPrefix.Definition.Count > 0) - { + //if (unitPrefix.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) @@ -161,11 +165,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedDomain.Count > 0) - { + //if (unitPrefix.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -174,11 +178,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedPerson.Count > 0) - { + //if (unitPrefix.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -187,11 +191,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.HyperLink.Count > 0) - { + //if (unitPrefix.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -200,7 +204,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -218,8 +222,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); - if (unitPrefix.Alias.Count > 0) - { + //if (unitPrefix.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) @@ -228,15 +232,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - if (unitPrefix.Definition.Count > 0) - { + //if (unitPrefix.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) @@ -245,11 +249,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedDomain.Count > 0) - { + //if (unitPrefix.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -258,11 +262,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedPerson.Count > 0) - { + //if (unitPrefix.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -271,11 +275,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.HyperLink.Count > 0) - { + //if (unitPrefix.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -284,7 +288,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -314,8 +318,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (unitPrefix.Alias.Count > 0) - { + //if (unitPrefix.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) @@ -324,15 +328,15 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); - if (unitPrefix.Definition.Count > 0) - { + //if (unitPrefix.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) @@ -341,11 +345,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedDomain.Count > 0) - { + //if (unitPrefix.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -354,11 +358,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.ExcludedPerson.Count > 0) - { + //if (unitPrefix.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -367,11 +371,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (unitPrefix.HyperLink.Count > 0) - { + //if (unitPrefix.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -380,7 +384,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -442,6 +446,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -495,6 +504,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -512,6 +526,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -529,6 +548,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -546,6 +570,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 95403c531..ba7ad024a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -93,8 +97,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - if (userPreference.ExcludedDomain.Count > 0) - { + //if (userPreference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -103,11 +107,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userPreference.ExcludedPerson.Count > 0) - { + //if (userPreference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -116,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -134,8 +138,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - if (userPreference.ExcludedDomain.Count > 0) - { + //if (userPreference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -144,11 +148,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userPreference.ExcludedPerson.Count > 0) - { + //if (userPreference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -157,7 +161,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -188,8 +192,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); - if (userPreference.ExcludedDomain.Count > 0) - { + //if (userPreference.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -198,11 +202,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userPreference.ExcludedPerson.Count > 0) - { + //if (userPreference.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -211,7 +215,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -289,6 +293,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -306,6 +315,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index cbbd33c88..da37d21a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -101,8 +105,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - if (userRuleVerification.Violation.Count > 0) - { + //if (userRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -111,7 +115,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.1.0": @@ -119,8 +123,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - if (userRuleVerification.ExcludedDomain.Count > 0) - { + //if (userRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userRuleVerification.ExcludedPerson.Count > 0) - { + //if (userRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,7 +146,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -168,8 +172,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - if (userRuleVerification.Violation.Count > 0) - { + //if (userRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -178,7 +182,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.2.0": @@ -186,8 +190,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - if (userRuleVerification.ExcludedDomain.Count > 0) - { + //if (userRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -196,11 +200,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userRuleVerification.ExcludedPerson.Count > 0) - { + //if (userRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -209,7 +213,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -237,8 +241,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - if (userRuleVerification.Violation.Count > 0) - { + //if (userRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -247,7 +251,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; case "1.3.0": @@ -266,8 +270,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); - if (userRuleVerification.ExcludedDomain.Count > 0) - { + //if (userRuleVerification.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -276,11 +280,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (userRuleVerification.ExcludedPerson.Count > 0) - { + //if (userRuleVerification.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -289,7 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("executedOn"u8); @@ -317,8 +321,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - if (userRuleVerification.Violation.Count > 0) - { + //if (userRuleVerification.Violation.Count > 0) + //{ writer.WriteStartArray("violation"u8); foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) @@ -327,7 +331,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} break; default: @@ -393,6 +397,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -410,6 +419,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -571,6 +585,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListViolation && objectListViolation.Any()) { writer.WriteStartArray("violation"u8); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index e17e14787..ea2a7fd36 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -68,6 +68,10 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); + + writer.WriteStartObject(); + writer.WriteEndObject(); + return; } @@ -78,8 +82,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); - if (valueGroup.Alias.Count > 0) - { + //if (valueGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -88,11 +92,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.Category.Count > 0) - { + //if (valueGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -101,13 +105,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - if (valueGroup.Definition.Count > 0) - { + //if (valueGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -116,11 +120,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedDomain.Count > 0) - { + //if (valueGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -129,11 +133,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedPerson.Count > 0) - { + //if (valueGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -142,11 +146,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.HyperLink.Count > 0) - { + //if (valueGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -155,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -171,8 +175,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); - if (valueGroup.Alias.Count > 0) - { + //if (valueGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -181,11 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.Category.Count > 0) - { + //if (valueGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -194,13 +198,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - if (valueGroup.Definition.Count > 0) - { + //if (valueGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -209,11 +213,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedDomain.Count > 0) - { + //if (valueGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -222,11 +226,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedPerson.Count > 0) - { + //if (valueGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -235,11 +239,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.HyperLink.Count > 0) - { + //if (valueGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -248,7 +252,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -276,8 +280,8 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - if (valueGroup.Alias.Count > 0) - { + //if (valueGroup.Alias.Count > 0) + //{ writer.WriteStartArray("alias"u8); foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) @@ -286,11 +290,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.Category.Count > 0) - { + //if (valueGroup.Category.Count > 0) + //{ writer.WriteStartArray("category"u8); foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) @@ -299,13 +303,13 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); - if (valueGroup.Definition.Count > 0) - { + //if (valueGroup.Definition.Count > 0) + //{ writer.WriteStartArray("definition"u8); foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) @@ -314,11 +318,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedDomain.Count > 0) - { + //if (valueGroup.ExcludedDomain.Count > 0) + //{ writer.WriteStartArray("excludedDomain"u8); foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) @@ -327,11 +331,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.ExcludedPerson.Count > 0) - { + //if (valueGroup.ExcludedPerson.Count > 0) + //{ writer.WriteStartArray("excludedPerson"u8); foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) @@ -340,11 +344,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} - if (valueGroup.HyperLink.Count > 0) - { + //if (valueGroup.HyperLink.Count > 0) + //{ writer.WriteStartArray("hyperLink"u8); foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) @@ -353,7 +357,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM } writer.WriteEndArray(); - } + //} writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -413,6 +417,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListAlias && objectListAlias.Any()) { writer.WriteStartArray("alias"u8); @@ -430,6 +439,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListCategory && objectListCategory.Any()) { writer.WriteStartArray("category"u8); @@ -465,6 +479,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) { writer.WriteStartArray("definition"u8); @@ -482,6 +501,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) { writer.WriteStartArray("excludedDomain"u8); @@ -499,6 +523,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) { writer.WriteStartArray("excludedPerson"u8); @@ -516,6 +545,11 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter return; } + if (value == null) + { + break; + } + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) { writer.WriteStartArray("hyperLink"u8); From 0fcfde77803642cfe82ea017d4212ac298af5d98 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 6 Nov 2024 15:08:44 +0100 Subject: [PATCH 20/34] Upgrades and fixes according to Annex.C3 Integration Tests --- .../ActionItemResolver.cs | 6 +- .../ActualFiniteStateListResolver.cs | 6 +- .../ActualFiniteStateResolver.cs | 6 +- .../AutoGenDtoDeserializer/AliasResolver.cs | 6 +- .../AndExpressionResolver.cs | 6 +- .../ApprovalResolver.cs | 6 +- .../ArrayParameterTypeResolver.cs | 6 +- .../BinaryNoteResolver.cs | 6 +- .../BinaryRelationshipResolver.cs | 6 +- .../BinaryRelationshipRuleResolver.cs | 6 +- .../AutoGenDtoDeserializer/BookResolver.cs | 6 +- .../BooleanParameterTypeResolver.cs | 6 +- .../AutoGenDtoDeserializer/BoundsResolver.cs | 6 +- .../BuiltInRuleVerificationResolver.cs | 6 +- .../CategoryResolver.cs | 6 +- .../ChangeProposalResolver.cs | 6 +- .../ChangeRequestResolver.cs | 6 +- .../CitationResolver.cs | 6 +- .../AutoGenDtoDeserializer/ColorResolver.cs | 6 +- .../CommonFileStoreResolver.cs | 6 +- .../CompoundParameterTypeResolver.cs | 6 +- .../ConstantResolver.cs | 9 +- .../ContractChangeNoticeResolver.cs | 6 +- .../CyclicRatioScaleResolver.cs | 6 +- .../DateParameterTypeResolver.cs | 6 +- .../DateTimeParameterTypeResolver.cs | 6 +- .../DecompositionRuleResolver.cs | 6 +- .../DefinitionResolver.cs | 6 +- ...ependentParameterTypeAssignmentResolver.cs | 6 +- .../DerivedQuantityKindResolver.cs | 6 +- .../DerivedUnitResolver.cs | 6 +- .../DiagramCanvasResolver.cs | 6 +- .../DiagramEdgeResolver.cs | 6 +- .../DiagramObjectResolver.cs | 6 +- .../DomainFileStoreResolver.cs | 6 +- .../DomainOfExpertiseGroupResolver.cs | 6 +- .../DomainOfExpertiseResolver.cs | 6 +- .../ElementDefinitionResolver.cs | 6 +- .../ElementUsageResolver.cs | 6 +- .../EmailAddressResolver.cs | 6 +- ...ineeringModelDataDiscussionItemResolver.cs | 6 +- .../EngineeringModelDataNoteResolver.cs | 6 +- .../EngineeringModelResolver.cs | 6 +- .../EngineeringModelSetupResolver.cs | 6 +- .../EnumerationParameterTypeResolver.cs | 6 +- .../EnumerationValueDefinitionResolver.cs | 6 +- .../ExclusiveOrExpressionResolver.cs | 6 +- .../ExternalIdentifierMapResolver.cs | 6 +- .../AutoGenDtoDeserializer/FileResolver.cs | 6 +- .../FileRevisionResolver.cs | 6 +- .../FileTypeResolver.cs | 6 +- .../AutoGenDtoDeserializer/FolderResolver.cs | 6 +- .../GlossaryResolver.cs | 6 +- .../AutoGenDtoDeserializer/GoalResolver.cs | 6 +- .../HyperLinkResolver.cs | 6 +- .../IdCorrespondenceResolver.cs | 6 +- ...ependentParameterTypeAssignmentResolver.cs | 6 +- .../IntervalScaleResolver.cs | 6 +- .../IterationResolver.cs | 6 +- .../IterationSetupResolver.cs | 6 +- .../LinearConversionUnitResolver.cs | 6 +- .../LogEntryChangelogItemResolver.cs | 6 +- .../LogarithmicScaleResolver.cs | 6 +- .../MappingToReferenceScaleResolver.cs | 6 +- .../ModelLogEntryResolver.cs | 6 +- .../ModelReferenceDataLibraryResolver.cs | 6 +- .../ModellingThingReferenceResolver.cs | 6 +- .../MultiRelationshipResolver.cs | 6 +- .../MultiRelationshipRuleResolver.cs | 6 +- .../NaturalLanguageResolver.cs | 6 +- .../NestedElementResolver.cs | 6 +- .../NestedParameterResolver.cs | 6 +- .../NotExpressionResolver.cs | 6 +- .../AutoGenDtoDeserializer/OptionResolver.cs | 6 +- .../OrExpressionResolver.cs | 6 +- .../OrdinalScaleResolver.cs | 6 +- .../OrganizationResolver.cs | 6 +- .../OrganizationalParticipantResolver.cs | 6 +- .../OwnedStyleResolver.cs | 6 +- .../AutoGenDtoDeserializer/PageResolver.cs | 6 +- .../ParameterGroupResolver.cs | 6 +- .../ParameterOverrideResolver.cs | 6 +- .../ParameterOverrideValueSetResolver.cs | 20 +- .../ParameterResolver.cs | 6 +- .../ParameterSubscriptionResolver.cs | 6 +- .../ParameterSubscriptionValueSetResolver.cs | 9 +- .../ParameterTypeComponentResolver.cs | 6 +- .../ParameterValueSetResolver.cs | 21 +- .../ParameterizedCategoryRuleResolver.cs | 6 +- .../ParametricConstraintResolver.cs | 6 +- .../ParticipantPermissionResolver.cs | 6 +- .../ParticipantResolver.cs | 6 +- .../ParticipantRoleResolver.cs | 6 +- .../PersonPermissionResolver.cs | 6 +- .../AutoGenDtoDeserializer/PersonResolver.cs | 6 +- .../PersonRoleResolver.cs | 6 +- .../AutoGenDtoDeserializer/PointResolver.cs | 6 +- .../PossibleFiniteStateListResolver.cs | 6 +- .../PossibleFiniteStateResolver.cs | 6 +- .../PrefixedUnitResolver.cs | 6 +- .../PublicationResolver.cs | 6 +- .../QuantityKindFactorResolver.cs | 6 +- .../RatioScaleResolver.cs | 6 +- .../ReferenceSourceResolver.cs | 6 +- .../ReferencerRuleResolver.cs | 6 +- .../RelationalExpressionResolver.cs | 9 +- .../RelationshipParameterValueResolver.cs | 9 +- .../RequestForDeviationResolver.cs | 6 +- .../RequestForWaiverResolver.cs | 6 +- .../RequirementResolver.cs | 6 +- ...irementsContainerParameterValueResolver.cs | 9 +- .../RequirementsGroupResolver.cs | 6 +- .../RequirementsSpecificationResolver.cs | 6 +- .../ReviewItemDiscrepancyResolver.cs | 6 +- .../RuleVerificationListResolver.cs | 6 +- .../RuleViolationResolver.cs | 6 +- .../SampledFunctionParameterTypeResolver.cs | 9 +- .../ScaleReferenceQuantityValueResolver.cs | 6 +- .../ScaleValueDefinitionResolver.cs | 6 +- .../AutoGenDtoDeserializer/SectionResolver.cs | 6 +- .../SharedStyleResolver.cs | 6 +- .../SimpleParameterValueResolver.cs | 9 +- .../SimpleQuantityKindResolver.cs | 6 +- .../SimpleUnitResolver.cs | 6 +- .../SiteDirectoryDataAnnotationResolver.cs | 6 +- ...SiteDirectoryDataDiscussionItemResolver.cs | 6 +- .../SiteDirectoryResolver.cs | 6 +- .../SiteDirectoryThingReferenceResolver.cs | 6 +- .../SiteLogEntryResolver.cs | 6 +- .../SiteReferenceDataLibraryResolver.cs | 6 +- .../SolutionResolver.cs | 6 +- .../SpecializedQuantityKindResolver.cs | 6 +- .../StakeHolderValueMapResolver.cs | 6 +- .../StakeHolderValueMapSettingsResolver.cs | 6 +- .../StakeholderResolver.cs | 6 +- .../StakeholderValueResolver.cs | 6 +- .../TelephoneNumberResolver.cs | 6 +- .../AutoGenDtoDeserializer/TermResolver.cs | 6 +- .../TextParameterTypeResolver.cs | 6 +- .../TextualNoteResolver.cs | 6 +- .../TimeOfDayParameterTypeResolver.cs | 6 +- .../UnitFactorResolver.cs | 6 +- .../UnitPrefixResolver.cs | 6 +- .../UserPreferenceResolver.cs | 6 +- .../UserRuleVerificationResolver.cs | 6 +- .../ValueGroupResolver.cs | 6 +- .../ActionItemSerializer.cs | 664 ++++---- .../ActualFiniteStateListSerializer.cs | 458 +++-- .../ActualFiniteStateSerializer.cs | 314 ++-- .../AutoGenDtoSerializer/AliasSerializer.cs | 249 ++- .../AndExpressionSerializer.cs | 307 ++-- .../ApprovalSerializer.cs | 270 ++- .../ArrayParameterTypeSerializer.cs | 722 ++++---- .../BinaryNoteSerializer.cs | 333 ++-- .../BinaryRelationshipRuleSerializer.cs | 515 +++--- .../BinaryRelationshipSerializer.cs | 392 ++--- .../AutoGenDtoSerializer/BookSerializer.cs | 370 ++-- .../BooleanParameterTypeSerializer.cs | 566 +++--- .../AutoGenDtoSerializer/BoundsSerializer.cs | 263 ++- .../BuiltInRuleVerificationSerializer.cs | 347 ++-- .../CategorySerializer.cs | 645 +++---- .../ChangeProposalSerializer.cs | 625 +++---- .../ChangeRequestSerializer.cs | 618 +++---- .../CitationSerializer.cs | 263 ++- .../AutoGenDtoSerializer/ColorSerializer.cs | 256 ++- .../CommonFileStoreSerializer.cs | 407 ++--- .../CompoundParameterTypeSerializer.cs | 644 +++---- .../ConstantSerializer.cs | 596 +++---- .../ContractChangeNoticeSerializer.cs | 625 +++---- .../CyclicRatioScaleSerializer.cs | 701 ++++---- .../DateParameterTypeSerializer.cs | 566 +++--- .../DateTimeParameterTypeSerializer.cs | 566 +++--- .../DecompositionRuleSerializer.cs | 597 +++---- .../DefinitionSerializer.cs | 457 +++-- ...endentParameterTypeAssignmentSerializer.cs | 223 ++- .../DerivedQuantityKindSerializer.cs | 730 ++++---- .../DerivedUnitSerializer.cs | 551 +++--- .../DiagramCanvasSerializer.cs | 362 ++-- .../DiagramEdgeSerializer.cs | 529 +++--- .../DiagramObjectSerializer.cs | 472 +++-- .../DomainFileStoreSerializer.cs | 414 ++--- .../DomainOfExpertiseGroupSerializer.cs | 559 +++--- .../DomainOfExpertiseSerializer.cs | 559 +++--- .../ElementDefinitionSerializer.cs | 922 +++++----- .../ElementUsageSerializer.cs | 731 ++++---- .../EmailAddressSerializer.cs | 242 ++- ...eeringModelDataDiscussionItemSerializer.cs | 278 ++- .../EngineeringModelDataNoteSerializer.cs | 400 ++--- .../EngineeringModelSerializer.cs | 658 ++++--- .../EngineeringModelSetupSerializer.cs | 900 +++++----- .../EnumerationParameterTypeSerializer.cs | 644 +++---- .../EnumerationValueDefinitionSerializer.cs | 473 +++-- .../ExclusiveOrExpressionSerializer.cs | 307 ++-- .../ExternalIdentifierMapSerializer.cs | 366 ++-- .../FileRevisionSerializer.cs | 351 ++-- .../AutoGenDtoSerializer/FileSerializer.cs | 411 ++--- .../FileTypeSerializer.cs | 566 +++--- .../AutoGenDtoSerializer/FolderSerializer.cs | 280 ++- .../GlossarySerializer.cs | 638 +++---- .../AutoGenDtoSerializer/GoalSerializer.cs | 488 +++--- .../HyperLinkSerializer.cs | 249 ++- .../IdCorrespondenceSerializer.cs | 242 ++- ...endentParameterTypeAssignmentSerializer.cs | 223 ++- .../IntervalScaleSerializer.cs | 694 ++++---- .../IterationSerializer.cs | 1515 ++++++++--------- .../IterationSetupSerializer.cs | 311 ++-- .../LinearConversionUnitSerializer.cs | 494 +++--- .../LogEntryChangelogItemSerializer.cs | 264 ++- .../LogarithmicScaleSerializer.cs | 801 ++++----- .../MappingToReferenceScaleSerializer.cs | 242 ++- .../ModelLogEntrySerializer.cs | 553 +++--- .../ModelReferenceDataLibrarySerializer.cs | 1481 +++++++--------- .../ModellingThingReferenceSerializer.cs | 242 ++- .../MultiRelationshipRuleSerializer.cs | 580 +++---- .../MultiRelationshipSerializer.cs | 457 +++-- .../NaturalLanguageSerializer.cs | 249 ++- .../NestedElementSerializer.cs | 392 ++--- .../NestedParameterSerializer.cs | 287 ++-- .../NotExpressionSerializer.cs | 235 ++- .../AutoGenDtoSerializer/OptionSerializer.cs | 631 +++---- .../OrExpressionSerializer.cs | 307 ++-- .../OrdinalScaleSerializer.cs | 701 ++++---- .../OrganizationSerializer.cs | 249 ++- .../OrganizationalParticipantSerializer.cs | 203 +-- .../OwnedStyleSerializer.cs | 546 +++--- .../AutoGenDtoSerializer/PageSerializer.cs | 370 ++-- .../ParameterGroupSerializer.cs | 255 ++- .../ParameterOverrideSerializer.cs | 400 ++--- .../ParameterOverrideValueSetSerializer.cs | 272 ++- .../ParameterSerializer.cs | 515 +++--- .../ParameterSubscriptionSerializer.cs | 314 ++-- ...ParameterSubscriptionValueSetSerializer.cs | 248 ++- .../ParameterTypeComponentSerializer.cs | 266 ++- .../ParameterValueSetSerializer.cs | 313 ++-- .../ParameterizedCategoryRuleSerializer.cs | 566 +++--- .../ParametricConstraintSerializer.cs | 330 ++-- .../ParticipantPermissionSerializer.cs | 251 ++- .../ParticipantRoleSerializer.cs | 559 +++--- .../ParticipantSerializer.cs | 335 ++-- .../PersonPermissionSerializer.cs | 251 ++- .../PersonRoleSerializer.cs | 559 +++--- .../AutoGenDtoSerializer/PersonSerializer.cs | 629 ++++--- .../AutoGenDtoSerializer/PointSerializer.cs | 249 ++- .../PossibleFiniteStateListSerializer.cs | 649 +++---- .../PossibleFiniteStateSerializer.cs | 473 +++-- .../PrefixedUnitSerializer.cs | 480 +++--- .../PublicationSerializer.cs | 393 ++--- .../QuantityKindFactorSerializer.cs | 242 ++- .../RatioScaleSerializer.cs | 694 ++++---- .../ReferenceSourceSerializer.cs | 676 ++++---- .../ReferencerRuleSerializer.cs | 580 +++---- .../RelationalExpressionSerializer.cs | 272 ++- .../RelationshipParameterValueSerializer.cs | 263 ++- .../RequestForDeviationSerializer.cs | 618 +++---- .../RequestForWaiverSerializer.cs | 618 +++---- .../RequirementSerializer.cs | 735 ++++---- ...ementsContainerParameterValueSerializer.cs | 263 ++- .../RequirementsGroupSerializer.cs | 685 ++++---- .../RequirementsSpecificationSerializer.cs | 771 ++++----- .../ReviewItemDiscrepancySerializer.cs | 681 ++++---- .../RuleVerificationListSerializer.cs | 551 +++--- .../RuleViolationSerializer.cs | 314 ++-- .../SampledFunctionParameterTypeSerializer.cs | 515 +++--- .../ScaleReferenceQuantityValueSerializer.cs | 242 ++- .../ScaleValueDefinitionSerializer.cs | 480 +++--- .../AutoGenDtoSerializer/SectionSerializer.cs | 370 ++-- .../SerializerProvider.cs | 63 +- .../SharedStyleSerializer.cs | 546 +++--- .../SimpleParameterValueSerializer.cs | 265 ++- .../SimpleQuantityKindSerializer.cs | 659 +++---- .../SimpleUnitSerializer.cs | 480 +++--- .../SiteDirectoryDataAnnotationSerializer.cs | 389 ++--- ...teDirectoryDataDiscussionItemSerializer.cs | 278 ++- .../SiteDirectorySerializer.cs | 1154 ++++++------- .../SiteDirectoryThingReferenceSerializer.cs | 242 ++- .../SiteLogEntrySerializer.cs | 553 +++--- .../SiteReferenceDataLibrarySerializer.cs | 1448 +++++++--------- .../SolutionSerializer.cs | 263 ++- .../SpecializedQuantityKindSerializer.cs | 666 +++----- .../StakeHolderValueMapSerializer.cs | 803 ++++----- .../StakeHolderValueMapSettingsSerializer.cs | 293 ++-- .../StakeholderSerializer.cs | 551 +++--- .../StakeholderValueSerializer.cs | 488 +++--- .../TelephoneNumberSerializer.cs | 314 ++-- .../AutoGenDtoSerializer/TermSerializer.cs | 480 +++--- .../TextParameterTypeSerializer.cs | 566 +++--- .../TextualNoteSerializer.cs | 327 ++-- .../TimeOfDayParameterTypeSerializer.cs | 566 +++--- .../UnitFactorSerializer.cs | 242 ++- .../UnitPrefixSerializer.cs | 487 +++--- .../UserPreferenceSerializer.cs | 242 ++- .../UserRuleVerificationSerializer.cs | 347 ++-- .../ValueGroupSerializer.cs | 488 +++--- .../DtoSerializer/IThingSerializer.cs | 15 + 294 files changed, 30904 insertions(+), 40022 deletions(-) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index 886d54a35..81ac2b50b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index 3df83fcdf..b4e715a54 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index 8e5616e1f..e4bfb8917 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index a9d83dab8..a21a60780 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index b17fe3a94..a555636ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index 1378b5439..d10cf77d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index 8d8cb1a3c..d54336e54 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index 150164e5b..359bc749e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index 350edb31d..2f4a6addf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index 89539ffe2..309c2010d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index 4c2240528..982609cac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index a1ccc896e..302db7082 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index 064b09dc6..bbb3a0735 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index 83eb3dbdf..3d8ff5028 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index 45ad0f807..cbbf71b32 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index ec4313f4f..80d7e9470 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index 81da64c3c..a0ed550a1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index 6cd195a75..31ff11912 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index 64f3c820a..6425b478e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index cbabb3ccb..0474e8556 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index 7d46e2a25..429f85a86 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index 0a6290ba7..c45d2664b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -197,10 +197,9 @@ public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) constant.ThingPreference = thingPreferenceProperty.GetString(); } } - if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - if(valueProperty.ValueKind == JsonValueKind.Array) + if (valueProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index 440dc5ea1..25e95b05e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index 5eb7acbbb..1adf7095c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index 1ad2f7457..5cbc1b5cb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index d3c3a6620..4633e4089 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index 5ca9ea740..f45fcb366 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 23ee6d215..712225614 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index e9c7e003e..a0d427660 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index 29b993504..f157236d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index 89be5f946..102e572e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index 2500cd181..2b1080899 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index eff757305..acbae661d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index 832cebd8f..e22f2ba6c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index c0aae96a8..de5efff51 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index 13f635805..a69fab53b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index d25fec368..041a2e065 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index a3a1186f2..8a238983a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index 84b8ff183..07fc39549 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index eecf1b006..e832f7d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index fdf634937..e9d3be319 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index 96f218979..0b3b320cd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index 612285fbd..8b6eba2b9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index d4a42835d..9c21ab1f1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index 82e9978ae..d11b4fabc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index c3965c910..7f41d597b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index 808237cf3..950fef19b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index af3557a53..2283d6bc8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index 56606ebe4..3a1760d00 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index 84b0ed63e..8043ec649 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 7e2cff570..a645e5341 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index 7f7cdba90..63f9f95d5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 1b6baf58d..da5022e50 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index 9139e52c2..a37b35c01 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index f08292f97..d94fbce3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index 8ea5d617f..d87de4344 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index e66252ef9..0617d32e9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index 4101ad9c1..2ee94f5ed 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index e2dd7c61b..4a0ff8ff6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index 439a668af..b19ad1c80 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index 0408618a5..16f446464 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index c795f5d20..509d2322e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index 6645e5c3a..7564addd3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index 0f7b7671a..ea925bbb0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index 3ad4b47e3..9124eebf8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 978be2fa5..b7f39f2b9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index 3bcd0fcde..309492a58 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index 28ee1e416..70cd05c15 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index 5631e7be2..c1643d61d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index a01154c7b..ad46d4314 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index f9cfec896..2610a3117 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index c261de473..b40cbbcb2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index 736d57d6b..c0e9d99de 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index dd39926d4..a6f71f8ac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index 45a5bd143..b04c2cbc9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index 35ec33a77..0252036c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index 8544a4a27..a06136294 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index 1480eb752..0b70c326f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index fa4a569a8..4882e5f6a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index 802b3aab3..af5258df7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 06806abb8..5ad816d24 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index e6ef2acc5..510ee80dc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index df4bee086..11c8b3d14 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -68,7 +68,7 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - if(computedProperty.ValueKind == JsonValueKind.Array) + if (computedProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -99,10 +99,9 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.ExcludedPerson.Add(element.GetGuid()); } } - if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - if(formulaProperty.ValueKind == JsonValueKind.Array) + if (formulaProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -117,10 +116,9 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } } - if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - if(manualProperty.ValueKind == JsonValueKind.Array) + if (manualProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -159,10 +157,9 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.ParameterValueSet = parameterValueSetProperty.GetGuid(); } } - if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) { - if(publishedProperty.ValueKind == JsonValueKind.Array) + if (publishedProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -177,10 +174,9 @@ public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElemen parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); } } - if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - if(referenceProperty.ValueKind == JsonValueKind.Array) + if (referenceProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index 57a1bb26b..90f13c303 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index babcc8d7a..036b50d15 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index b0019a730..fbfa4450b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -81,10 +81,9 @@ public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonEl parameterSubscriptionValueSet.ExcludedPerson.Add(element.GetGuid()); } } - if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - if(manualProperty.ValueKind == JsonValueKind.Array) + if (manualProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index ffef8aae8..4a650859d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index 856685cba..a9d4a4410 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -89,10 +89,9 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ActualState = actualStateProperty.GetGuid(); } } - if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - if(computedProperty.ValueKind == JsonValueKind.Array) + if (computedProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -123,10 +122,9 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ExcludedPerson.Add(element.GetGuid()); } } - if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - if(formulaProperty.ValueKind == JsonValueKind.Array) + if (formulaProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -141,10 +139,9 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); } } - if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - if(manualProperty.ValueKind == JsonValueKind.Array) + if (manualProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -171,10 +168,9 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); } } - if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) { - if(publishedProperty.ValueKind == JsonValueKind.Array) + if (publishedProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); @@ -189,10 +185,9 @@ public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonEl parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); } } - if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - if(referenceProperty.ValueKind == JsonValueKind.Array) + if (referenceProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index dfe057d1a..6fb4e5d0a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index 1f561b0ce..5ddce38d7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index b9aa667df..b58ecf48d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index 74f51f146..820b963ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index bb8ff8fc8..2742ae225 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index b07ec56eb..2d03a89d5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index f1d7642ba..f0ba867fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index b5a8d0600..063e6dbea 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index b4ee1a93c..a9cdd608d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index 0095626d3..dea8d31e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index 0d6650557..5e55f886c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index e75645efd..28d53a0bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index da21655f2..d46a326c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index 9643ed834..2406fcbd1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 5e34f7b5d..bf4d97a07 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index 866134a1e..55ebb5eb9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index 314f255e9..d3a473077 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index 9b8f7786b..912798d55 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -141,10 +141,9 @@ public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jso relationalExpression.ThingPreference = thingPreferenceProperty.GetString(); } } - if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - if(valueProperty.ValueKind == JsonValueKind.Array) + if (valueProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index 254b03fde..08cf24540 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -129,10 +129,9 @@ public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonEleme relationshipParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } - if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - if(valueProperty.ValueKind == JsonValueKind.Array) + if (valueProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index 2db7e9a48..210eae8b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index 85dbdb22d..3e3ee4989 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index af1bcb7ce..83fe79d50 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index e70b398d2..4a3416cfd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -129,10 +129,9 @@ public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject( requirementsContainerParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } - if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - if(valueProperty.ValueKind == JsonValueKind.Array) + if (valueProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index 9bb9827c9..00474c7a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index d5ef4da2e..88be8d42b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index 39d475e53..84139d605 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index 7031f4a51..b7f82649b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index fd9f030fe..42e18210f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index 4a77d6f6f..9b29fd145 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -135,10 +135,9 @@ public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonEle { sampledFunctionParameterType.IndependentParameterType.AddRange(independentParameterTypeProperty.ToOrderedItemCollection()); } - if (jsonElement.TryGetProperty("interpolationPeriod"u8, out var interpolationPeriodProperty)) { - if(interpolationPeriodProperty.ValueKind == JsonValueKind.Array) + if (interpolationPeriodProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index 76b791ff5..b9a29a9fc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index 1b02a134e..48bd0fbf2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index abbd3dc14..6ac9398e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index 413764f91..a3718665f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index b4969c27f..e417f203d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition @@ -129,10 +129,9 @@ public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jso simpleParameterValue.ThingPreference = thingPreferenceProperty.GetString(); } } - if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - if(valueProperty.ValueKind == JsonValueKind.Array) + if (valueProperty.ValueKind == JsonValueKind.Array) { var newValueArrayItems = new List(); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index e63896767..4983d1647 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index 3f72f5ca8..758253cac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index b3aa780c6..f06dc09f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 9c98ce00e..5380d655a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index 27c9db3a0..a1b7aefc8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index f40b568be..73ca4f387 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index 4f8550a33..17876d3eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index 81e490656..b52c064a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index db7714f65..19a9367db 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index fa950d2ee..30ddf36aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index 589efb71e..b18dbb25c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index 581771269..642ca5a28 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index c77fa91f7..c5874af63 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index 9070fe184..8f9e1ec73 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 15cf8e744..2b0e4aa74 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index fd8dc64c0..57b74e4e9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index 0e258bb60..399c53b81 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index dbe622619..af6462a4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index cdf6a4a41..de4d14105 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index bd5290b29..9d57e4e8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index 06a2d3b5e..f936da37d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index 293e3e25e..44fe0a53e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index 8924818aa..71ed3e2fd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index a95c3a155..903e15289 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index f3b101fa1..05b5f6a2c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,33 +79,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.1.0"); writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); - //if (actionItem.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - //if (actionItem.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -117,7 +105,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.ClassKind.ToString()); writer.WritePropertyName("closeOutDate"u8); - if(actionItem.CloseOutDate.HasValue) + if (actionItem.CloseOutDate.HasValue) { writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -132,46 +120,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (actionItem.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (actionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -183,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(actionItem.PrimaryAnnotatedThing.HasValue) + if (actionItem.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } @@ -192,34 +168,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (actionItem.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (actionItem.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -230,33 +199,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.2.0"); writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); - //if (actionItem.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - //if (actionItem.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -264,7 +225,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.ClassKind.ToString()); writer.WritePropertyName("closeOutDate"u8); - if(actionItem.CloseOutDate.HasValue) + if (actionItem.CloseOutDate.HasValue) { writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -279,46 +240,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (actionItem.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (actionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -330,7 +279,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(actionItem.PrimaryAnnotatedThing.HasValue) + if (actionItem.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } @@ -339,34 +288,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (actionItem.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (actionItem.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -379,43 +321,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.3.0"); writer.WritePropertyName("actionee"u8); writer.WriteStringValue(actionItem.Actionee); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(actionItem.Actor.HasValue) - { - writer.WriteStringValue(actionItem.Actor.Value); - } - else + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(approvedByItem); } - //if (actionItem.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); - //if (actionItem.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(actionItem.Classification.ToString()); @@ -423,7 +347,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.ClassKind.ToString()); writer.WritePropertyName("closeOutDate"u8); - if(actionItem.CloseOutDate.HasValue) + if (actionItem.CloseOutDate.HasValue) { writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -438,46 +362,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (actionItem.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("dueDate"u8); writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (actionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actionItem.Iid); @@ -489,7 +401,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actionItem.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(actionItem.PrimaryAnnotatedThing.HasValue) + if (actionItem.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); } @@ -498,34 +410,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (actionItem.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actionItem.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (actionItem.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(actionItem.Status.ToString()); @@ -541,6 +446,150 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ActionItem actionItem) + { + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if (actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -553,14 +602,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + { + return; + } + + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { switch(propertyName.ToLower()) { case "actionee": - if(!AllowedVersionsPerProperty["actionee"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("actionee"u8); if(value != null) @@ -572,31 +633,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteNullValue(); } - break; - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - break; case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -614,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -632,11 +665,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -654,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -672,11 +695,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -690,11 +708,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "closeoutdate": - if(!AllowedVersionsPerProperty["closeOutDate"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("closeOutDate"u8); if(value != null) @@ -708,11 +721,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "closeoutstatement": - if(!AllowedVersionsPerProperty["closeOutStatement"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("closeOutStatement"u8); if(value != null) @@ -726,11 +734,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -744,11 +747,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -762,11 +760,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -784,11 +777,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "duedate": - if(!AllowedVersionsPerProperty["dueDate"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("dueDate"u8); if(value != null) @@ -802,11 +790,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -824,11 +807,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -846,11 +824,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -864,11 +837,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -882,11 +850,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -900,11 +863,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -918,11 +876,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -936,11 +889,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -958,11 +906,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -976,11 +919,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -994,11 +932,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1016,11 +949,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -1034,11 +962,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1052,11 +975,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index e9e1ee8d1..d659dff23 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,109 +77,81 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("actualState"u8); - //if (actualFiniteStateList.ActualState.Count > 0) - //{ - writer.WriteStartArray("actualState"u8); - - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualStateItem); - } + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludeOption"u8); - //if (actualFiniteStateList.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("actualState"u8); - //if (actualFiniteStateList.ActualState.Count > 0) - //{ - writer.WriteStartArray("actualState"u8); - - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualStateItem); - } + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (actualFiniteStateList.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -191,77 +159,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("actualState"u8); - //if (actualFiniteStateList.ActualState.Count > 0) - //{ - writer.WriteStartArray("actualState"u8); - - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualStateItem); - } + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (actualFiniteStateList.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -269,18 +217,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -289,69 +233,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("actualState"u8); - if(actualFiniteStateList.Actor.HasValue) - { - writer.WriteStringValue(actualFiniteStateList.Actor.Value); - } - else + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(actualStateItem); } - //if (actualFiniteStateList.ActualState.Count > 0) - //{ - writer.WriteStartArray("actualState"u8); - - foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualStateItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (actualFiniteStateList.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteStateList.Iid); @@ -359,18 +277,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (actualFiniteStateList.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); @@ -384,6 +298,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ActualFiniteStateList actualFiniteStateList) + { + throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -396,32 +390,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "actualstate": - if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -439,11 +427,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -457,11 +440,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -479,11 +457,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -501,11 +474,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeoption": - if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -523,11 +491,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -541,11 +504,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -559,11 +517,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -577,11 +530,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblefinitestatelist": - if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +547,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -617,11 +560,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 677d21611..00401afc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -87,18 +83,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Iid); writer.WritePropertyName("kind"u8); writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WriteStartArray("possibleState"u8); - //if (actualFiniteState.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -107,31 +99,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -139,18 +123,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); - //if (actualFiniteState.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -159,31 +139,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -191,18 +163,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); - //if (actualFiniteState.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -211,44 +179,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(actualFiniteState.Actor.HasValue) - { - writer.WriteStringValue(actualFiniteState.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (actualFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (actualFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(actualFiniteState.Iid); @@ -256,18 +205,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(actualFiniteState.Kind.ToString()); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); - //if (actualFiniteState.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleStateItem); - } + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(actualFiniteState.RevisionNumber); @@ -281,6 +226,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -293,32 +299,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -332,11 +332,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -354,11 +349,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "kind": - if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("kind"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblestate": - if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -452,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -470,11 +435,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 9f11aae8c..864e2ac0b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -100,31 +96,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (alias.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (alias.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -143,31 +131,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (alias.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (alias.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -184,46 +164,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(alias.Actor.HasValue) - { - writer.WriteStringValue(alias.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(alias.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (alias.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (alias.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(alias.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,32 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -296,11 +306,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -314,11 +319,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -336,11 +336,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "issynonym": - if(!AllowedVersionsPerProperty["isSynonym"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isSynonym"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index d6231dc43..b00163305 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -87,49 +83,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (andExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (andExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (andExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -137,49 +121,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (andExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (andExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (andExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -187,62 +159,39 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (andExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(andExpression.Actor.HasValue) - { - writer.WriteStringValue(andExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (andExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (andExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(andExpression.Iid); @@ -250,18 +199,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (andExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(andExpression.ThingPreference); @@ -273,6 +218,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -285,32 +289,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -324,11 +322,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -346,11 +339,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -444,11 +412,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 5be1c81a9..c33692a65 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -91,31 +87,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (approval.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (approval.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -140,31 +128,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (approval.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (approval.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -181,17 +161,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(approval.Actor.HasValue) - { - writer.WriteStringValue(approval.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(approval.Author); writer.WritePropertyName("classification"u8); @@ -202,31 +171,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(approval.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (approval.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (approval.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(approval.Iid); @@ -248,6 +209,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -260,32 +282,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -299,11 +315,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -317,11 +328,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -335,11 +341,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -353,11 +354,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -371,11 +367,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -393,11 +384,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -415,11 +401,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -433,11 +414,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -451,11 +427,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -469,11 +440,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -487,11 +453,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -505,11 +466,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index f56e6177a..b14333457 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,85 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (arrayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (arrayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (arrayParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (arrayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); - //if (arrayParameterType.Dimension.Count > 0) - //{ - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (arrayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -180,111 +152,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (arrayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (arrayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (arrayParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (arrayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); - //if (arrayParameterType.Dimension.Count > 0) - //{ - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (arrayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (arrayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (arrayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -307,111 +247,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (arrayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (arrayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (arrayParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (arrayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); - //if (arrayParameterType.Dimension.Count > 0) - //{ - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (arrayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (arrayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (arrayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -436,121 +344,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(arrayParameterType.Actor.HasValue) + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(arrayParameterType.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (arrayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (arrayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (arrayParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (arrayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("dimension"u8); - //if (arrayParameterType.Dimension.Count > 0) - //{ - writer.WriteStartArray("dimension"u8); - - foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dimensionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (arrayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (arrayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (arrayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(arrayParameterType.Iid); @@ -580,6 +446,126 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ArrayParameterType arrayParameterType) + { + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -592,32 +578,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -635,11 +615,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -657,11 +632,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -675,11 +645,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "component": - if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -697,11 +662,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -719,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "dimension": - if(!AllowedVersionsPerProperty["dimension"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -741,11 +696,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -763,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -785,11 +730,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -807,11 +747,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -825,11 +760,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -843,11 +773,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isfinalized": - if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isFinalized"u8); if(value != null) @@ -861,11 +786,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "istensor": - if(!AllowedVersionsPerProperty["isTensor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isTensor"u8); if(value != null) @@ -879,11 +799,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -897,11 +812,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -915,11 +825,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -933,11 +838,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -951,11 +851,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -969,11 +864,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 3c564e71b..777dfff69 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,48 +79,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.1.0"); writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); - //if (binaryNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -145,48 +129,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.2.0"); writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); - //if (binaryNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -207,61 +179,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(binaryNote.Actor.HasValue) - { - writer.WriteStringValue(binaryNote.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("caption"u8); writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); - //if (binaryNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryNote.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fileType"u8); writer.WriteStringValue(binaryNote.FileType); @@ -287,6 +236,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not BinaryNote binaryNote) + { + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -299,32 +319,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "caption": - if(!AllowedVersionsPerProperty["caption"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("caption"u8); if(value != null) @@ -338,11 +352,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -360,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -378,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -396,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -418,11 +412,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -440,11 +429,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "filetype": - if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fileType"u8); if(value != null) @@ -458,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -476,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -494,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -512,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -530,11 +494,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -548,11 +507,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -566,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index c6b17c474..47c9d58d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (binaryRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (binaryRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - //if (binaryRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -145,74 +129,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (binaryRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (binaryRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - //if (binaryRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -237,74 +201,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (binaryRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (binaryRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - //if (binaryRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -331,84 +275,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(binaryRelationshipRule.Actor.HasValue) + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(binaryRelationshipRule.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (binaryRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (binaryRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("forwardRelationshipName"u8); writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); - //if (binaryRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationshipRule.Iid); @@ -440,6 +354,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not BinaryRelationshipRule binaryRelationshipRule) + { + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -452,32 +460,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -513,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -535,11 +527,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -557,11 +544,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -579,11 +561,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "forwardrelationshipname": - if(!AllowedVersionsPerProperty["forwardRelationshipName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("forwardRelationshipName"u8); if(value != null) @@ -597,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -619,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -637,11 +604,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "inverserelationshipname": - if(!AllowedVersionsPerProperty["inverseRelationshipName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("inverseRelationshipName"u8); if(value != null) @@ -655,11 +617,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -673,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -691,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -709,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relationshipcategory": - if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("relationshipCategory"u8); if(value != null) @@ -727,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -745,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -763,11 +695,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourcecategory": - if(!AllowedVersionsPerProperty["sourceCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sourceCategory"u8); if(value != null) @@ -781,11 +708,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "targetcategory": - if(!AllowedVersionsPerProperty["targetCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("targetCategory"u8); if(value != null) @@ -799,11 +721,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index cff25743b..65d2e153c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,18 +77,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); - //if (binaryRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); @@ -109,46 +101,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (binaryRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -156,18 +136,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (binaryRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -178,46 +154,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (binaryRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -227,18 +191,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (binaryRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -251,56 +211,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(binaryRelationship.Actor.HasValue) + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(binaryRelationship.Actor.Value); + writer.WriteStringValue(categoryItem); } - else - { - writer.WriteNullValue(); - } - - //if (binaryRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (binaryRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (binaryRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(binaryRelationship.Iid); @@ -310,18 +248,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(binaryRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (binaryRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(binaryRelationship.RevisionNumber); @@ -339,6 +273,82 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not BinaryRelationship binaryRelationship) + { + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -351,32 +361,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -394,11 +398,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -412,11 +411,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -434,11 +428,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -456,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -474,11 +458,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -492,11 +471,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -510,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -528,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -550,11 +514,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -568,11 +527,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "source": - if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("source"u8); if(value != null) @@ -586,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "target": - if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("target"u8); if(value != null) @@ -604,11 +553,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index e03274358..77116b70e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (book.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (book.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (book.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -134,66 +118,50 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); - //if (book.Section.Count > 0) - //{ - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (book.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (book.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (book.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -205,18 +173,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); - //if (book.Section.Count > 0) - //{ - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -225,58 +189,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(book.Actor.HasValue) - { - writer.WriteStringValue(book.Actor.Value); - } - else + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - //if (book.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(book.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (book.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (book.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(book.Iid); @@ -288,18 +230,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(book.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); - //if (book.Section.Count > 0) - //{ - writer.WriteStartArray("section"u8); - - foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(sectionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(book.ShortName); @@ -313,6 +251,82 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Book book) + { + throw new ArgumentException("The thing shall be a Book", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -325,32 +339,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -386,11 +389,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -404,11 +402,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -426,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -448,11 +436,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -466,11 +449,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -484,11 +462,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -502,11 +475,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -520,11 +488,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -538,11 +501,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "section": - if(!AllowedVersionsPerProperty["section"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -560,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -578,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index db44f2e2e..519f7bc28 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (booleanParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (booleanParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (booleanParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (booleanParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -150,85 +130,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (booleanParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (booleanParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (booleanParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (booleanParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (booleanParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (booleanParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -247,85 +203,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (booleanParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (booleanParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (booleanParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (booleanParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (booleanParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (booleanParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -346,95 +278,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(booleanParameterType.Actor.HasValue) + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(booleanParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (booleanParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (booleanParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (booleanParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (booleanParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (booleanParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (booleanParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(booleanParameterType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not BooleanParameterType booleanParameterType) + { + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +601,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index ef430cb66..cee69a24a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (bounds.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (bounds.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -130,31 +118,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (bounds.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (bounds.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -177,44 +157,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(bounds.Actor.HasValue) - { - writer.WriteStringValue(bounds.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (bounds.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (bounds.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("height"u8); writer.WriteNumberValue(bounds.Height); @@ -242,6 +203,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Bounds bounds) + { + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -254,32 +274,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -293,11 +307,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -315,11 +324,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -337,11 +341,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "height": - if(!AllowedVersionsPerProperty["height"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("height"u8); if(value != null) @@ -355,11 +354,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -373,11 +367,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -391,11 +380,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -409,11 +393,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -427,11 +406,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -445,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "width": - if(!AllowedVersionsPerProperty["width"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("width"u8); if(value != null) @@ -463,11 +432,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "x": - if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("x"u8); if(value != null) @@ -481,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "y": - if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("y"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index e6ebf2a62..9d091d63e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); writer.WritePropertyName("executedOn"u8); - if(builtInRuleVerification.ExecutedOn.HasValue) + if (builtInRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -104,53 +100,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - - //if (builtInRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (builtInRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (builtInRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(builtInRuleVerification.ExecutedOn.HasValue) + if (builtInRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -171,53 +146,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); writer.WritePropertyName("status"u8); writer.WriteStringValue(builtInRuleVerification.Status.ToString()); - - //if (builtInRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (builtInRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (builtInRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(builtInRuleVerification.ExecutedOn.HasValue) + if (builtInRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -240,64 +194,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(builtInRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - - //if (builtInRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(builtInRuleVerification.Actor.HasValue) - { - writer.WriteStringValue(builtInRuleVerification.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (builtInRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (builtInRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(builtInRuleVerification.ExecutedOn.HasValue) + if (builtInRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -320,19 +242,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(builtInRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(builtInRuleVerification.ThingPreference); - - //if (builtInRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in builtInRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; default: throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); @@ -341,6 +250,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not BuiltInRuleVerification builtInRuleVerification) + { + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -353,32 +328,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -392,11 +361,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -414,11 +378,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -436,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "executedon": - if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("executedOn"u8); if(value != null) @@ -454,11 +408,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -472,11 +421,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isActive"u8); if(value != null) @@ -490,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -508,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -526,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -544,11 +473,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -562,11 +486,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -578,28 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteNullValue(); } - break; - case "violation": - if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) - { - return; - } - - if (value == null) - { - break; - } - - if (value is IEnumerable objectListViolation && objectListViolation.Any()) - { - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - writer.WriteEndArray(); - } break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the BuiltInRuleVerification"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index 6d20bee16..7b9033821 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (category.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (category.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (category.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -130,105 +114,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(category.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - //if (category.PermissibleClass.Count > 0) - //{ - writer.WriteStartArray("permissibleClass"u8); - - foreach(var permissibleClassItem in category.PermissibleClass) - { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); - //if (category.SuperCategory.Count > 0) - //{ - writer.WriteStartArray("superCategory"u8); - - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(superCategoryItem); - } + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (category.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (category.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (category.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (category.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (category.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -240,105 +196,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - //if (category.PermissibleClass.Count > 0) - //{ - writer.WriteStartArray("permissibleClass"u8); - - foreach(var permissibleClassItem in category.PermissibleClass) - { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); - //if (category.SuperCategory.Count > 0) - //{ - writer.WriteStartArray("superCategory"u8); - - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(superCategoryItem); - } + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (category.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (category.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (category.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (category.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (category.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -350,117 +278,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - //if (category.PermissibleClass.Count > 0) - //{ - writer.WriteStartArray("permissibleClass"u8); - - foreach(var permissibleClassItem in category.PermissibleClass) - { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); - //if (category.SuperCategory.Count > 0) - //{ - writer.WriteStartArray("superCategory"u8); - - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(superCategoryItem); - } + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(category.Actor.HasValue) - { - writer.WriteStringValue(category.Actor.Value); - } - else + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (category.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (category.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (category.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (category.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (category.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(category.Iid); @@ -472,35 +362,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); - //if (category.PermissibleClass.Count > 0) - //{ - writer.WriteStartArray("permissibleClass"u8); - - foreach(var permissibleClassItem in category.PermissibleClass) - { - writer.WriteStringValue(permissibleClassItem.ToString()); - } + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(category.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); - //if (category.SuperCategory.Count > 0) - //{ - writer.WriteStartArray("superCategory"u8); - - foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(superCategoryItem); - } + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(category.ThingPreference); @@ -512,6 +394,112 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -524,32 +512,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -567,11 +549,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -585,11 +562,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -607,11 +579,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -629,11 +596,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -651,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -673,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -691,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isabstract": - if(!AllowedVersionsPerProperty["isAbstract"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isAbstract"u8); if(value != null) @@ -709,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -727,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -745,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -763,11 +695,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "permissibleclass": - if(!AllowedVersionsPerProperty["permissibleClass"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -785,11 +712,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -803,11 +725,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -821,11 +738,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "supercategory": - if(!AllowedVersionsPerProperty["superCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -843,11 +755,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index f67ac8059..870607ca4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (changeProposal.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); - //if (changeProposal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -119,44 +107,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeProposal.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeProposal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeProposal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -168,7 +144,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeProposal.PrimaryAnnotatedThing.HasValue) + if (changeProposal.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); } @@ -177,34 +153,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeProposal.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeProposal.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -213,33 +182,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (changeProposal.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); - //if (changeProposal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -251,44 +212,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeProposal.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeProposal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeProposal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -300,7 +249,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeProposal.PrimaryAnnotatedThing.HasValue) + if (changeProposal.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); } @@ -309,34 +258,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeProposal.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeProposal.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -347,43 +289,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(changeProposal.Actor.HasValue) - { - writer.WriteStringValue(changeProposal.Actor.Value); - } - else + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(approvedByItem); } - //if (changeProposal.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); - //if (changeProposal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeRequest"u8); writer.WriteStringValue(changeProposal.ChangeRequest); @@ -395,44 +319,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeProposal.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeProposal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeProposal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeProposal.Iid); @@ -444,7 +356,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeProposal.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeProposal.PrimaryAnnotatedThing.HasValue) + if (changeProposal.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); } @@ -453,34 +365,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeProposal.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeProposal.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeProposal.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeProposal.Status.ToString()); @@ -496,6 +401,134 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ChangeProposal changeProposal) + { + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -508,32 +541,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +578,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -569,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +608,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "changerequest": - if(!AllowedVersionsPerProperty["changeRequest"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("changeRequest"u8); if(value != null) @@ -609,11 +621,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -627,11 +634,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -645,11 +647,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -663,11 +660,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -681,11 +673,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -703,11 +690,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -725,11 +707,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -747,11 +724,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -765,11 +737,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -783,11 +750,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -801,11 +763,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -819,11 +776,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -837,11 +789,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -859,11 +806,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -877,11 +819,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -895,11 +832,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -917,11 +849,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -935,11 +862,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -953,11 +875,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index 66b34e2cc..e37ceb3c7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (changeRequest.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); - //if (changeRequest.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -117,44 +105,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeRequest.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeRequest.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeRequest.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -166,7 +142,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeRequest.PrimaryAnnotatedThing.HasValue) + if (changeRequest.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); } @@ -175,34 +151,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeRequest.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeRequest.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -211,33 +180,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (changeRequest.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); - //if (changeRequest.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -247,44 +208,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeRequest.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeRequest.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeRequest.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -296,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeRequest.PrimaryAnnotatedThing.HasValue) + if (changeRequest.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); } @@ -305,34 +254,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeRequest.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeRequest.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -343,43 +285,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(changeRequest.Actor.HasValue) + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(changeRequest.Actor.Value); + writer.WriteStringValue(approvedByItem); } - else - { - writer.WriteNullValue(); - } - - //if (changeRequest.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); - //if (changeRequest.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(changeRequest.Classification.ToString()); @@ -389,44 +313,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (changeRequest.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (changeRequest.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (changeRequest.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(changeRequest.Iid); @@ -438,7 +350,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(changeRequest.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(changeRequest.PrimaryAnnotatedThing.HasValue) + if (changeRequest.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); } @@ -447,34 +359,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (changeRequest.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(changeRequest.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (changeRequest.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(changeRequest.Status.ToString()); @@ -490,6 +395,132 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -502,32 +533,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -545,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -563,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -603,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -621,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -639,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -657,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -679,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -701,11 +686,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -723,11 +703,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -741,11 +716,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -759,11 +729,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -777,11 +742,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -795,11 +755,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -813,11 +768,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -835,11 +785,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -853,11 +798,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -871,11 +811,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -893,11 +828,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -911,11 +841,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -929,11 +854,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index 10e2c3279..373db2357 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -102,31 +98,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (citation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (citation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -149,31 +137,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (citation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (citation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -196,44 +176,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(citation.Actor.HasValue) - { - writer.WriteStringValue(citation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (citation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (citation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(citation.Iid); @@ -261,6 +222,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Citation citation) + { + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -273,32 +293,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -312,11 +326,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -334,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -356,11 +360,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -374,11 +373,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isadaptation": - if(!AllowedVersionsPerProperty["isAdaptation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isAdaptation"u8); if(value != null) @@ -392,11 +386,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "location": - if(!AllowedVersionsPerProperty["location"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("location"u8); if(value != null) @@ -410,11 +399,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -428,11 +412,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "remark": - if(!AllowedVersionsPerProperty["remark"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("remark"u8); if(value != null) @@ -446,11 +425,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -464,11 +438,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -482,11 +451,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "source": - if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("source"u8); if(value != null) @@ -500,11 +464,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 21226aba2..6118ad542 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -102,31 +98,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (color.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (color.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -147,31 +135,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (color.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (color.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -190,46 +170,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(color.Actor.HasValue) - { - writer.WriteStringValue(color.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("blue"u8); writer.WriteNumberValue(color.Blue); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (color.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (color.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("green"u8); writer.WriteNumberValue(color.Green); @@ -253,6 +214,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Color color) + { + throw new ArgumentException("The thing shall be a Color", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -265,32 +283,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "blue": - if(!AllowedVersionsPerProperty["blue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("blue"u8); if(value != null) @@ -304,11 +316,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -322,11 +329,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -344,11 +346,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -366,11 +363,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "green": - if(!AllowedVersionsPerProperty["green"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("green"u8); if(value != null) @@ -384,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -402,11 +389,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -420,11 +402,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -438,11 +415,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "red": - if(!AllowedVersionsPerProperty["red"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("red"u8); if(value != null) @@ -456,11 +428,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -474,11 +441,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 75386f456..21e542da3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,31 +81,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); - //if (commonFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (commonFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -126,57 +114,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (commonFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (commonFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (commonFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (commonFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -195,57 +167,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (commonFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (commonFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (commonFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (commonFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -262,72 +218,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(commonFileStore.Actor.HasValue) - { - writer.WriteStringValue(commonFileStore.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(commonFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (commonFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (commonFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (commonFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (commonFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(commonFileStore.Iid); @@ -349,6 +278,81 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not CommonFileStore commonFileStore) + { + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -361,32 +365,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -400,11 +398,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -418,11 +411,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -440,11 +428,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -462,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "file": - if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -484,11 +462,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "folder": - if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -506,11 +479,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -524,11 +492,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -542,11 +505,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -560,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -578,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -596,11 +544,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index acff7df8a..00413de50 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,72 +77,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (compoundParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (compoundParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (compoundParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (compoundParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (compoundParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -165,98 +141,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (compoundParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (compoundParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (compoundParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (compoundParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (compoundParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (compoundParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (compoundParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -277,98 +225,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (compoundParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (compoundParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (compoundParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (compoundParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (compoundParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (compoundParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (compoundParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -391,108 +311,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(compoundParameterType.Actor.HasValue) + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(compoundParameterType.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (compoundParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (compoundParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); - //if (compoundParameterType.Component.Count > 0) - //{ - writer.WriteStartArray("component"u8); - - foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(componentItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (compoundParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (compoundParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (compoundParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (compoundParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(compoundParameterType.Iid); @@ -520,6 +402,114 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -532,32 +522,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -575,11 +559,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -597,11 +576,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -615,11 +589,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "component": - if(!AllowedVersionsPerProperty["component"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -637,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -659,11 +623,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -681,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -703,11 +657,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -725,11 +674,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -743,11 +687,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -761,11 +700,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isfinalized": - if(!AllowedVersionsPerProperty["isFinalized"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isFinalized"u8); if(value != null) @@ -779,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -797,11 +726,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -815,11 +739,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -833,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -851,11 +765,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -869,11 +778,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index e19efbb0a..ee6d45fd2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (constant.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (constant.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (constant.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (constant.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -147,7 +127,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(constant.RevisionNumber); writer.WritePropertyName("scale"u8); - if(constant.Scale.HasValue) + if (constant.Scale.HasValue) { writer.WriteStringValue(constant.Scale.Value); } @@ -162,85 +142,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (constant.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (constant.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (constant.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (constant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (constant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (constant.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -256,7 +212,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(constant.RevisionNumber); writer.WritePropertyName("scale"u8); - if(constant.Scale.HasValue) + if (constant.Scale.HasValue) { writer.WriteStringValue(constant.Scale.Value); } @@ -271,85 +227,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (constant.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (constant.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (constant.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (constant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (constant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (constant.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -365,7 +297,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(constant.RevisionNumber); writer.WritePropertyName("scale"u8); - if(constant.Scale.HasValue) + if (constant.Scale.HasValue) { writer.WriteStringValue(constant.Scale.Value); } @@ -382,95 +314,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(constant.Actor.HasValue) + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(constant.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (constant.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (constant.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (constant.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (constant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (constant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (constant.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(constant.Iid); @@ -486,7 +384,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(constant.RevisionNumber); writer.WritePropertyName("scale"u8); - if(constant.Scale.HasValue) + if (constant.Scale.HasValue) { writer.WriteStringValue(constant.Scale.Value); } @@ -508,6 +406,114 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Constant constant) + { + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -520,32 +526,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -563,11 +563,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -603,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -625,11 +610,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -647,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -669,11 +644,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -691,11 +661,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -709,11 +674,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -727,11 +687,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -745,11 +700,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -763,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -781,11 +726,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -799,11 +739,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -817,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -835,11 +765,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -853,11 +778,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 9db6fcb14..b25d66857 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (contractChangeNotice.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); - //if (contractChangeNotice.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -119,44 +107,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (contractChangeNotice.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (contractChangeNotice.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (contractChangeNotice.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -168,7 +144,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); } @@ -177,34 +153,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (contractChangeNotice.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (contractChangeNotice.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -213,33 +182,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (contractChangeNotice.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); - //if (contractChangeNotice.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -251,44 +212,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (contractChangeNotice.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (contractChangeNotice.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (contractChangeNotice.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -300,7 +249,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); } @@ -309,34 +258,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (contractChangeNotice.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (contractChangeNotice.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -347,43 +289,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(contractChangeNotice.Actor.HasValue) - { - writer.WriteStringValue(contractChangeNotice.Actor.Value); - } - else + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(approvedByItem); } - //if (contractChangeNotice.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); - //if (contractChangeNotice.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeProposal"u8); writer.WriteStringValue(contractChangeNotice.ChangeProposal); @@ -395,44 +319,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (contractChangeNotice.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (contractChangeNotice.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (contractChangeNotice.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(contractChangeNotice.Iid); @@ -444,7 +356,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(contractChangeNotice.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(contractChangeNotice.PrimaryAnnotatedThing.HasValue) + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); } @@ -453,34 +365,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (contractChangeNotice.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(contractChangeNotice.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (contractChangeNotice.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(contractChangeNotice.Status.ToString()); @@ -496,6 +401,134 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ContractChangeNotice contractChangeNotice) + { + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -508,32 +541,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +578,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -569,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +608,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "changeproposal": - if(!AllowedVersionsPerProperty["changeProposal"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("changeProposal"u8); if(value != null) @@ -609,11 +621,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -627,11 +634,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -645,11 +647,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -663,11 +660,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -681,11 +673,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -703,11 +690,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -725,11 +707,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -747,11 +724,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -765,11 +737,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -783,11 +750,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -801,11 +763,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -819,11 +776,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -837,11 +789,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -859,11 +806,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -877,11 +819,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -895,11 +832,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -917,11 +849,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -935,11 +862,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -953,11 +875,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index eee1f859c..1b6157ce1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (cyclicRatioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (cyclicRatioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (cyclicRatioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -163,88 +143,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (cyclicRatioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (cyclicRatioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (cyclicRatioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (cyclicRatioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (cyclicRatioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (cyclicRatioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -254,18 +210,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -289,88 +241,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (cyclicRatioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (cyclicRatioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (cyclicRatioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (cyclicRatioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (cyclicRatioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (cyclicRatioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -380,18 +308,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -417,98 +341,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (cyclicRatioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(cyclicRatioScale.Actor.HasValue) + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(cyclicRatioScale.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (cyclicRatioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (cyclicRatioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (cyclicRatioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (cyclicRatioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (cyclicRatioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(cyclicRatioScale.Iid); @@ -518,18 +408,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (cyclicRatioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); @@ -555,18 +441,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(cyclicRatioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (cyclicRatioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -576,6 +458,128 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not CyclicRatioScale cyclicRatioScale) + { + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -588,32 +592,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -631,11 +629,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -649,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -671,11 +659,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -693,11 +676,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -715,11 +693,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -737,11 +710,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -755,11 +723,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -773,11 +736,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ismaximuminclusive": - if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) @@ -791,11 +749,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isminimuminclusive": - if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) @@ -809,11 +762,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mappingtoreferencescale": - if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -831,11 +779,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "maximumpermissiblevalue": - if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) @@ -849,11 +792,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minimumpermissiblevalue": - if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minimumPermissibleValue"u8); if(value != null) @@ -867,11 +805,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -885,11 +818,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modulus": - if(!AllowedVersionsPerProperty["modulus"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modulus"u8); if(value != null) @@ -903,11 +831,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -921,11 +844,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("negativeValueConnotation"u8); if(value != null) @@ -939,11 +857,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("numberSet"u8); if(value != null) @@ -957,11 +870,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("positiveValueConnotation"u8); if(value != null) @@ -975,11 +883,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -993,11 +896,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1011,11 +909,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1029,11 +922,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) @@ -1047,11 +935,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 1da9a8d68..03c724c3e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (dateParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -150,85 +130,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (dateParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -247,85 +203,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (dateParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -346,95 +278,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(dateParameterType.Actor.HasValue) + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(dateParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (dateParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateParameterType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DateParameterType dateParameterType) + { + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +601,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index 5bfab0a5f..237a0ad4a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (dateTimeParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateTimeParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateTimeParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateTimeParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -150,85 +130,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (dateTimeParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateTimeParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateTimeParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateTimeParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateTimeParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateTimeParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -247,85 +203,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (dateTimeParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateTimeParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateTimeParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateTimeParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateTimeParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateTimeParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -346,95 +278,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(dateTimeParameterType.Actor.HasValue) + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(dateTimeParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (dateTimeParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (dateTimeParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (dateTimeParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (dateTimeParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dateTimeParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (dateTimeParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dateTimeParameterType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DateTimeParameterType dateTimeParameterType) + { + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +601,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index 4d1c07d78..d2aca878b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (decompositionRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - //if (decompositionRule.ContainedCategory.Count > 0) - //{ - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedCategoryItem); - } + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - //if (decompositionRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (decompositionRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -143,7 +123,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(decompositionRule.IsDeprecated); writer.WritePropertyName("maxContained"u8); - if(decompositionRule.MaxContained.HasValue) + if (decompositionRule.MaxContained.HasValue) { writer.WriteNumberValue(decompositionRule.MaxContained.Value); } @@ -163,87 +143,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (decompositionRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - //if (decompositionRule.ContainedCategory.Count > 0) - //{ - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedCategoryItem); - } + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - //if (decompositionRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (decompositionRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (decompositionRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (decompositionRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -251,7 +207,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(decompositionRule.IsDeprecated); writer.WritePropertyName("maxContained"u8); - if(decompositionRule.MaxContained.HasValue) + if (decompositionRule.MaxContained.HasValue) { writer.WriteNumberValue(decompositionRule.MaxContained.Value); } @@ -273,87 +229,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (decompositionRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - //if (decompositionRule.ContainedCategory.Count > 0) - //{ - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedCategoryItem); - } + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - //if (decompositionRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (decompositionRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (decompositionRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (decompositionRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -361,7 +293,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(decompositionRule.IsDeprecated); writer.WritePropertyName("maxContained"u8); - if(decompositionRule.MaxContained.HasValue) + if (decompositionRule.MaxContained.HasValue) { writer.WriteNumberValue(decompositionRule.MaxContained.Value); } @@ -385,97 +317,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(decompositionRule.Actor.HasValue) + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(decompositionRule.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (decompositionRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); - //if (decompositionRule.ContainedCategory.Count > 0) - //{ - writer.WriteStartArray("containedCategory"u8); - - foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedCategoryItem); - } + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("containingCategory"u8); writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); - //if (decompositionRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (decompositionRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (decompositionRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (decompositionRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(decompositionRule.Iid); @@ -483,7 +381,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(decompositionRule.IsDeprecated); writer.WritePropertyName("maxContained"u8); - if(decompositionRule.MaxContained.HasValue) + if (decompositionRule.MaxContained.HasValue) { writer.WriteNumberValue(decompositionRule.MaxContained.Value); } @@ -512,6 +410,115 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -524,32 +531,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -567,11 +568,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -585,11 +581,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containedcategory": - if(!AllowedVersionsPerProperty["containedCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -607,11 +598,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "containingcategory": - if(!AllowedVersionsPerProperty["containingCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("containingCategory"u8); if(value != null) @@ -625,11 +611,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -647,11 +628,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -669,11 +645,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -691,11 +662,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -713,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -731,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -749,11 +705,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "maxcontained": - if(!AllowedVersionsPerProperty["maxContained"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maxContained"u8); if(value != null) @@ -767,11 +718,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mincontained": - if(!AllowedVersionsPerProperty["minContained"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minContained"u8); if(value != null) @@ -785,11 +731,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -803,11 +744,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -821,11 +757,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -839,11 +770,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -857,11 +783,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 6852ba246..8f5c73acd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,113 +77,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); + writer.WriteStartArray("citation"u8); - //if (definition.Citation.Count > 0) - //{ - writer.WriteStartArray("citation"u8); - - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(citationItem); - } + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); - //if (definition.Example.Count > 0) - //{ - writer.WriteStartArray("example"u8); - - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); writer.WritePropertyName("languageCode"u8); writer.WriteStringValue(definition.LanguageCode); + writer.WriteStartArray("note"u8); - //if (definition.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); + writer.WriteStartArray("citation"u8); - //if (definition.Citation.Count > 0) - //{ - writer.WriteStartArray("citation"u8); - - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(citationItem); - } + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); - //if (definition.Example.Count > 0) - //{ - writer.WriteStartArray("example"u8); - - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (definition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (definition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -195,79 +163,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); - //if (definition.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); + writer.WriteStartArray("citation"u8); - //if (definition.Citation.Count > 0) - //{ - writer.WriteStartArray("citation"u8); - - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(citationItem); - } + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); - //if (definition.Example.Count > 0) - //{ - writer.WriteStartArray("example"u8); - - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (definition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (definition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -275,18 +223,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); - //if (definition.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -295,71 +239,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("citation"u8); - if(definition.Actor.HasValue) + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(definition.Actor.Value); + writer.WriteStringValue(citationItem); } - else - { - writer.WriteNullValue(); - } - - //if (definition.Citation.Count > 0) - //{ - writer.WriteStartArray("citation"u8); - - foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(citationItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(definition.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); - //if (definition.Example.Count > 0) - //{ - writer.WriteStartArray("example"u8); - - foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(exampleItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (definition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (definition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(definition.Iid); @@ -367,18 +285,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(definition.LanguageCode); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); - //if (definition.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(definition.RevisionNumber); @@ -392,6 +306,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Definition definition) + { + throw new ArgumentException("The thing shall be a Definition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -404,32 +400,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "citation": - if(!AllowedVersionsPerProperty["citation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -447,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -465,11 +450,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -483,11 +463,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "example": - if(!AllowedVersionsPerProperty["example"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -505,11 +480,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -527,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -549,11 +514,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -567,11 +527,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -585,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -603,11 +553,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "note": - if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -625,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -643,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 1812e52d1..abc688bdf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,37 +79,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); writer.WritePropertyName("measurementScale"u8); - if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) { writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); } @@ -133,50 +121,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(dependentParameterTypeAssignment.Actor.HasValue) - { - writer.WriteStringValue(dependentParameterTypeAssignment.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (dependentParameterTypeAssignment.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (dependentParameterTypeAssignment.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(dependentParameterTypeAssignment.Iid); writer.WritePropertyName("measurementScale"u8); - if(dependentParameterTypeAssignment.MeasurementScale.HasValue) + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) { writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); } @@ -201,6 +170,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -213,32 +244,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -252,11 +277,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -274,11 +294,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -296,11 +311,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -314,11 +324,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "measurementscale": - if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("measurementScale"u8); if(value != null) @@ -332,11 +337,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -350,11 +350,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -368,11 +363,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -386,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index cb1f96017..0217a3243 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (derivedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (derivedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (derivedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -143,33 +123,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (derivedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - //if (derivedQuantityKind.QuantityKindFactor.Count > 0) - //{ - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -180,87 +152,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (derivedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (derivedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (derivedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -270,33 +218,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (derivedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - //if (derivedQuantityKind.QuantityKindFactor.Count > 0) - //{ - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -307,87 +247,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (derivedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (derivedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (derivedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -397,33 +313,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (derivedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - //if (derivedQuantityKind.QuantityKindFactor.Count > 0) - //{ - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -436,97 +344,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(derivedQuantityKind.Actor.HasValue) - { - writer.WriteStringValue(derivedQuantityKind.Actor.Value); - } - else + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (derivedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (derivedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (derivedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedQuantityKind.Iid); @@ -536,33 +410,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (derivedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); - //if (derivedQuantityKind.QuantityKindFactor.Count > 0) - //{ - writer.WriteStartArray("quantityKindFactor"u8); - - foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(quantityKindFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); @@ -580,6 +446,126 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DerivedQuantityKind derivedQuantityKind) + { + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -592,32 +578,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -635,11 +615,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -657,11 +632,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -675,11 +645,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultscale": - if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultScale"u8); if(value != null) @@ -693,11 +658,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -715,11 +675,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -737,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -759,11 +709,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -781,11 +726,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -799,11 +739,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -817,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -835,11 +765,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -853,11 +778,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblescale": - if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -875,11 +795,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "quantitydimensionsymbol": - if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("quantityDimensionSymbol"u8); if(value != null) @@ -893,11 +808,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "quantitykindfactor": - if(!AllowedVersionsPerProperty["quantityKindFactor"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -915,11 +825,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -933,11 +838,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -951,11 +851,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -969,11 +864,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index 9ece18663..6a4d8ab39 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (derivedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (derivedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -132,88 +116,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(derivedUnit.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); - //if (derivedUnit.UnitFactor.Count > 0) - //{ - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (derivedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (derivedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -227,88 +187,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(derivedUnit.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); - //if (derivedUnit.UnitFactor.Count > 0) - //{ - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (derivedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (derivedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -324,98 +260,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedUnit.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); - //if (derivedUnit.UnitFactor.Count > 0) - //{ - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(derivedUnit.Actor.HasValue) + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(derivedUnit.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (derivedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (derivedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (derivedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (derivedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (derivedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(derivedUnit.Iid); @@ -431,18 +333,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(derivedUnit.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); - //if (derivedUnit.UnitFactor.Count > 0) - //{ - writer.WriteStartArray("unitFactor"u8); - - foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(unitFactorItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DerivedUnit derivedUnit) + { + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -525,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -631,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -649,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -667,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -685,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -703,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -721,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -739,11 +665,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unitfactor": - if(!AllowedVersionsPerProperty["unitFactor"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index a04c896c4..13d280f91 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramCanvas.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); - //if (diagramCanvas.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramCanvas.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramCanvas.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -148,61 +128,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramCanvas.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); - //if (diagramCanvas.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramCanvas.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramCanvas.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -217,71 +181,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("bounds"u8); - if(diagramCanvas.Actor.HasValue) - { - writer.WriteStringValue(diagramCanvas.Actor.Value); - } - else + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(boundsItem); } - //if (diagramCanvas.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); - //if (diagramCanvas.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); - - foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramCanvas.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramCanvas.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramCanvas.Iid); @@ -301,6 +239,78 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DiagramCanvas diagramCanvas) + { + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -313,32 +323,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "bounds": - if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -356,11 +360,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -374,11 +373,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -392,11 +386,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "diagramelement": - if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -414,11 +403,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -436,11 +420,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -458,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -476,11 +450,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -494,11 +463,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -512,11 +476,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -530,11 +489,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 72bd96c1c..e19dc97c6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,24 +77,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramEdge.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramEdge.DepictedThing.HasValue) + if (diagramEdge.DepictedThing.HasValue) { writer.WriteStringValue(diagramEdge.DepictedThing.Value); } @@ -107,81 +99,62 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramEdge.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramEdge.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramEdge.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramEdge.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - //if (diagramEdge.Point.Count > 0) - //{ - writer.WriteStartArray("point"u8); - - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramEdge.SharedStyle.HasValue) + if (diagramEdge.SharedStyle.HasValue) { writer.WriteStringValue(diagramEdge.SharedStyle.Value); } @@ -197,24 +170,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramEdge.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramEdge.DepictedThing.HasValue) + if (diagramEdge.DepictedThing.HasValue) { writer.WriteStringValue(diagramEdge.DepictedThing.Value); } @@ -223,81 +192,62 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramEdge.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramEdge.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramEdge.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramEdge.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - //if (diagramEdge.Point.Count > 0) - //{ - writer.WriteStartArray("point"u8); - - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramEdge.SharedStyle.HasValue) + if (diagramEdge.SharedStyle.HasValue) { writer.WriteStringValue(diagramEdge.SharedStyle.Value); } @@ -315,34 +265,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("bounds"u8); - if(diagramEdge.Actor.HasValue) - { - writer.WriteStringValue(diagramEdge.Actor.Value); - } - else + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(boundsItem); } - //if (diagramEdge.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramEdge.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramEdge.DepictedThing.HasValue) + if (diagramEdge.DepictedThing.HasValue) { writer.WriteStringValue(diagramEdge.DepictedThing.Value); } @@ -351,81 +287,62 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramEdge.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramEdge.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramEdge.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramEdge.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); - //if (diagramEdge.Point.Count > 0) - //{ - writer.WriteStartArray("point"u8); - - foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pointItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(diagramEdge.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramEdge.SharedStyle.HasValue) + if (diagramEdge.SharedStyle.HasValue) { writer.WriteStringValue(diagramEdge.SharedStyle.Value); } @@ -448,6 +365,121 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -460,32 +492,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "bounds": - if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -503,11 +529,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -521,11 +542,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "depictedthing": - if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("depictedThing"u8); if(value != null) @@ -539,11 +555,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "diagramelement": - if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -561,11 +572,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -583,11 +589,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -605,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -623,11 +619,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "localstyle": - if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -645,11 +636,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -663,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -681,11 +662,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "point": - if(!AllowedVersionsPerProperty["point"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -703,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -721,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sharedstyle": - if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sharedStyle"u8); if(value != null) @@ -739,11 +705,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "source": - if(!AllowedVersionsPerProperty["source"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("source"u8); if(value != null) @@ -757,11 +718,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "target": - if(!AllowedVersionsPerProperty["target"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("target"u8); if(value != null) @@ -775,11 +731,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 45514f249..e9ed53414 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,24 +77,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramObject.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramObject.DepictedThing.HasValue) + if (diagramObject.DepictedThing.HasValue) { writer.WriteStringValue(diagramObject.DepictedThing.Value); } @@ -107,60 +99,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramObject.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramObject.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramObject.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramObject.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -172,7 +149,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(diagramObject.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramObject.SharedStyle.HasValue) + if (diagramObject.SharedStyle.HasValue) { writer.WriteStringValue(diagramObject.SharedStyle.Value); } @@ -184,24 +161,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); - //if (diagramObject.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramObject.DepictedThing.HasValue) + if (diagramObject.DepictedThing.HasValue) { writer.WriteStringValue(diagramObject.DepictedThing.Value); } @@ -210,60 +183,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramObject.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramObject.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramObject.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramObject.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -275,7 +233,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(diagramObject.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramObject.SharedStyle.HasValue) + if (diagramObject.SharedStyle.HasValue) { writer.WriteStringValue(diagramObject.SharedStyle.Value); } @@ -289,34 +247,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("bounds"u8); - if(diagramObject.Actor.HasValue) + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(diagramObject.Actor.Value); + writer.WriteStringValue(boundsItem); } - else - { - writer.WriteNullValue(); - } - - //if (diagramObject.Bounds.Count > 0) - //{ - writer.WriteStartArray("bounds"u8); - foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(boundsItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(diagramObject.ClassKind.ToString()); writer.WritePropertyName("depictedThing"u8); - if(diagramObject.DepictedThing.HasValue) + if (diagramObject.DepictedThing.HasValue) { writer.WriteStringValue(diagramObject.DepictedThing.Value); } @@ -325,60 +269,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (diagramObject.DiagramElement.Count > 0) - //{ - writer.WriteStartArray("diagramElement"u8); + writer.WriteStartArray("diagramElement"u8); - foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramElementItem); - } + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("documentation"u8); writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); - //if (diagramObject.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (diagramObject.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); - //if (diagramObject.LocalStyle.Count > 0) - //{ - writer.WriteStartArray("localStyle"u8); - - foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(localStyleItem); - } + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -390,7 +319,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(diagramObject.RevisionNumber); writer.WritePropertyName("sharedStyle"u8); - if(diagramObject.SharedStyle.HasValue) + if (diagramObject.SharedStyle.HasValue) { writer.WriteStringValue(diagramObject.SharedStyle.Value); } @@ -409,6 +338,111 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DiagramObject diagramObject) + { + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -421,32 +455,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "bounds": - if(!AllowedVersionsPerProperty["bounds"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -464,11 +492,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -482,11 +505,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "depictedthing": - if(!AllowedVersionsPerProperty["depictedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("depictedThing"u8); if(value != null) @@ -500,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "diagramelement": - if(!AllowedVersionsPerProperty["diagramElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -522,11 +535,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "documentation": - if(!AllowedVersionsPerProperty["documentation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("documentation"u8); if(value != null) @@ -540,11 +548,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -562,11 +565,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -584,11 +582,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -602,11 +595,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "localstyle": - if(!AllowedVersionsPerProperty["localStyle"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -624,11 +612,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -642,11 +625,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -660,11 +638,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "resolution": - if(!AllowedVersionsPerProperty["resolution"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("resolution"u8); if(value != null) @@ -678,11 +651,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -696,11 +664,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sharedstyle": - if(!AllowedVersionsPerProperty["sharedStyle"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sharedStyle"u8); if(value != null) @@ -714,11 +677,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index 66cda0f2d..a78f18d7a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,31 +81,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); - //if (domainFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (domainFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -128,57 +116,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (domainFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (domainFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (domainFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -199,57 +171,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (domainFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (domainFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (domainFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -268,72 +224,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(domainFileStore.Actor.HasValue) - { - writer.WriteStringValue(domainFileStore.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainFileStore.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (domainFileStore.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainFileStore.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("file"u8); - //if (domainFileStore.File.Count > 0) - //{ - writer.WriteStartArray("file"u8); - - foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileItem); - } + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("folder"u8); - //if (domainFileStore.Folder.Count > 0) - //{ - writer.WriteStartArray("folder"u8); - - foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(folderItem); - } + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainFileStore.Iid); @@ -357,6 +286,83 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DomainFileStore domainFileStore) + { + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -369,32 +375,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -408,11 +408,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -426,11 +421,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -448,11 +438,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -470,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "file": - if(!AllowedVersionsPerProperty["file"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -492,11 +472,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "folder": - if(!AllowedVersionsPerProperty["folder"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -514,11 +489,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -532,11 +502,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ishidden": - if(!AllowedVersionsPerProperty["isHidden"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isHidden"u8); if(value != null) @@ -550,11 +515,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -568,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -586,11 +541,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -604,11 +554,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -622,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index 2f40b4152..62865f963 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertiseGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertiseGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); - //if (domainOfExpertiseGroup.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertiseGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -148,85 +128,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertiseGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertiseGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); - //if (domainOfExpertiseGroup.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertiseGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -243,85 +199,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertiseGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertiseGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); - //if (domainOfExpertiseGroup.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertiseGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -340,95 +272,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(domainOfExpertiseGroup.Actor.HasValue) + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(domainOfExpertiseGroup.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (domainOfExpertiseGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertiseGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domain"u8); - //if (domainOfExpertiseGroup.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertiseGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertiseGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertiseGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertiseGroup.Iid); @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) + { + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -525,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "domain": - if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -635,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -653,11 +604,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -671,11 +617,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -689,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -707,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -725,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -743,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index 5926b122d..59ad1fe4d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertise.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (domainOfExpertise.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertise.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertise.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -148,85 +128,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertise.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (domainOfExpertise.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertise.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertise.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertise.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertise.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -243,85 +199,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (domainOfExpertise.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (domainOfExpertise.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertise.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertise.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertise.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertise.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -340,95 +272,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(domainOfExpertise.Actor.HasValue) + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(domainOfExpertise.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (domainOfExpertise.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (domainOfExpertise.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (domainOfExpertise.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (domainOfExpertise.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (domainOfExpertise.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (domainOfExpertise.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(domainOfExpertise.Iid); @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not DomainOfExpertise domainOfExpertise) + { + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -529,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -635,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -653,11 +604,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -671,11 +617,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -689,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -707,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -725,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -743,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index e5e8db51e..c38a216cf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,72 +77,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (elementDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementDefinition.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - //if (elementDefinition.ContainedElement.Count > 0) - //{ - writer.WriteStartArray("containedElement"u8); - - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedElementItem); - } + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (elementDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -154,44 +130,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - //if (elementDefinition.Parameter.Count > 0) - //{ - writer.WriteStartArray("parameter"u8); - - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterItem); - } + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); - //if (elementDefinition.ParameterGroup.Count > 0) - //{ - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterGroupItem); - } + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); - //if (elementDefinition.ReferencedElement.Count > 0) - //{ - writer.WriteStartArray("referencedElement"u8); - - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedElementItem); - } + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -200,98 +164,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (elementDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementDefinition.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - //if (elementDefinition.ContainedElement.Count > 0) - //{ - writer.WriteStartArray("containedElement"u8); - - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedElementItem); - } + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (elementDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (elementDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -301,44 +237,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - //if (elementDefinition.Parameter.Count > 0) - //{ - writer.WriteStartArray("parameter"u8); - - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterItem); - } + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); - //if (elementDefinition.ParameterGroup.Count > 0) - //{ - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterGroupItem); - } + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); - //if (elementDefinition.ReferencedElement.Count > 0) - //{ - writer.WriteStartArray("referencedElement"u8); - - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedElementItem); - } + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -347,98 +271,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (elementDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementDefinition.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - //if (elementDefinition.ContainedElement.Count > 0) - //{ - writer.WriteStartArray("containedElement"u8); - - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedElementItem); - } + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (elementDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (elementDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -446,59 +342,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); - //if (elementDefinition.OrganizationalParticipant.Count > 0) - //{ - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - //if (elementDefinition.Parameter.Count > 0) - //{ - writer.WriteStartArray("parameter"u8); - - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterItem); - } + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); - //if (elementDefinition.ParameterGroup.Count > 0) - //{ - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterGroupItem); - } + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); - //if (elementDefinition.ReferencedElement.Count > 0) - //{ - writer.WriteStartArray("referencedElement"u8); - - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedElementItem); - } + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -509,108 +389,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(elementDefinition.Actor.HasValue) + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(elementDefinition.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (elementDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementDefinition.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); - //if (elementDefinition.ContainedElement.Count > 0) - //{ - writer.WriteStartArray("containedElement"u8); - - foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(containedElementItem); - } + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (elementDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (elementDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementDefinition.Iid); @@ -618,59 +460,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); - //if (elementDefinition.OrganizationalParticipant.Count > 0) - //{ - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); - //if (elementDefinition.Parameter.Count > 0) - //{ - writer.WriteStartArray("parameter"u8); - - foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterItem); - } + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parameterGroup"u8); - //if (elementDefinition.ParameterGroup.Count > 0) - //{ - writer.WriteStartArray("parameterGroup"u8); - - foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterGroupItem); - } + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referencedElement"u8); - //if (elementDefinition.ReferencedElement.Count > 0) - //{ - writer.WriteStartArray("referencedElement"u8); - - foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedElementItem); - } + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementDefinition.RevisionNumber); @@ -686,6 +512,150 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ElementDefinition elementDefinition) + { + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -698,32 +668,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -741,11 +705,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -763,11 +722,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -781,11 +735,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containedelement": - if(!AllowedVersionsPerProperty["containedElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -803,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -825,11 +769,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -847,11 +786,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -869,11 +803,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -891,11 +820,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -909,11 +833,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -927,11 +846,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -945,11 +859,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organizationalparticipant": - if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -967,11 +876,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -985,11 +889,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parameter": - if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1007,11 +906,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "parametergroup": - if(!AllowedVersionsPerProperty["parameterGroup"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1029,11 +923,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "referencedelement": - if(!AllowedVersionsPerProperty["referencedElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1051,11 +940,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1069,11 +953,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1087,11 +966,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 68b0ac006..e7bf082f4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,74 +77,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (elementUsage.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementUsage.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (elementUsage.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludeOption"u8); - //if (elementUsage.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementUsage.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -158,18 +134,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - //if (elementUsage.ParameterOverride.Count > 0) - //{ - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterOverrideItem); - } + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -178,100 +150,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (elementUsage.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementUsage.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (elementUsage.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); - //if (elementUsage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementUsage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (elementUsage.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementUsage.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -283,18 +227,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - //if (elementUsage.ParameterOverride.Count > 0) - //{ - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterOverrideItem); - } + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -303,100 +243,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (elementUsage.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementUsage.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (elementUsage.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); - //if (elementUsage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementUsage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (elementUsage.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementUsage.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -408,18 +320,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - //if (elementUsage.ParameterOverride.Count > 0) - //{ - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterOverrideItem); - } + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -430,110 +338,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(elementUsage.Actor.HasValue) + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(elementUsage.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (elementUsage.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (elementUsage.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (elementUsage.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("elementDefinition"u8); writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); - //if (elementUsage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (elementUsage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludeOption"u8); - //if (elementUsage.ExcludeOption.Count > 0) - //{ - writer.WriteStartArray("excludeOption"u8); - - foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludeOptionItem); - } + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (elementUsage.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(elementUsage.Iid); @@ -545,18 +415,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(elementUsage.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); - //if (elementUsage.ParameterOverride.Count > 0) - //{ - writer.WriteStartArray("parameterOverride"u8); - - foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterOverrideItem); - } + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(elementUsage.RevisionNumber); @@ -572,6 +438,124 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ElementUsage elementUsage) + { + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -584,32 +568,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -627,11 +605,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -649,11 +622,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -667,11 +635,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -689,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "elementdefinition": - if(!AllowedVersionsPerProperty["elementDefinition"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("elementDefinition"u8); if(value != null) @@ -707,11 +665,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -729,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -751,11 +699,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeoption": - if(!AllowedVersionsPerProperty["excludeOption"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -773,11 +716,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -795,11 +733,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -813,11 +746,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "interfaceend": - if(!AllowedVersionsPerProperty["interfaceEnd"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("interfaceEnd"u8); if(value != null) @@ -831,11 +759,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -849,11 +772,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -867,11 +785,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -885,11 +798,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parameteroverride": - if(!AllowedVersionsPerProperty["parameterOverride"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -907,11 +815,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -925,11 +828,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -943,11 +841,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index efba04dc1..6e15f24a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (emailAddress.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (emailAddress.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (emailAddress.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (emailAddress.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(emailAddress.Actor.HasValue) - { - writer.WriteStringValue(emailAddress.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (emailAddress.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (emailAddress.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(emailAddress.Iid); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EmailAddress emailAddress) + { + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("value"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "vcardtype": - if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("vcardType"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index 21cd14ec9..7709b4d2f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,31 +85,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -123,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); } @@ -145,31 +133,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -179,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); } @@ -195,17 +175,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(engineeringModelDataDiscussionItem.Actor.HasValue) - { - writer.WriteStringValue(engineeringModelDataDiscussionItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); writer.WritePropertyName("classKind"u8); @@ -214,31 +183,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); @@ -248,7 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(engineeringModelDataDiscussionItem.ReplyTo.HasValue) + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); } @@ -269,6 +230,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -281,32 +310,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -320,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -338,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -356,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -374,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -396,11 +399,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -418,11 +416,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -436,11 +429,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -454,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -472,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "replyto": - if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("replyTo"u8); if(value != null) @@ -490,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -508,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 91ecd65d9..06425018b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,44 +85,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (engineeringModelDataNote.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -136,7 +120,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); } @@ -145,17 +129,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (engineeringModelDataNote.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -170,44 +151,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (engineeringModelDataNote.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -217,7 +186,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); } @@ -226,17 +195,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (engineeringModelDataNote.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -245,17 +211,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(engineeringModelDataNote.Actor.HasValue) - { - writer.WriteStringValue(engineeringModelDataNote.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(engineeringModelDataNote.Author); writer.WritePropertyName("classKind"u8); @@ -264,44 +219,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (engineeringModelDataNote.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelDataNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelDataNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelDataNote.Iid); @@ -311,7 +254,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); } @@ -320,17 +263,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (engineeringModelDataNote.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); @@ -344,6 +284,93 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EngineeringModelDataNote engineeringModelDataNote) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -356,32 +383,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -395,11 +416,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -413,11 +429,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -431,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -449,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -471,11 +472,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -493,11 +489,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -533,11 +519,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -551,11 +532,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -569,11 +545,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -587,11 +558,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -609,11 +575,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -627,11 +588,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 9d86edd9f..8f273acab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,167 +79,123 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - //if (engineeringModel.CommonFileStore.Count > 0) - //{ - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - //if (engineeringModel.Iteration.Count > 0) - //{ - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationItem); - } + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (engineeringModel.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModel.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); + writer.WriteStartArray("book"u8); - //if (engineeringModel.Book.Count > 0) - //{ - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - //if (engineeringModel.CommonFileStore.Count > 0) - //{ - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModel.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModel.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); - //if (engineeringModel.GenericNote.Count > 0) - //{ - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(genericNoteItem); - } + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - //if (engineeringModel.Iteration.Count > 0) - //{ - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationItem); - } + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (engineeringModel.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); - //if (engineeringModel.ModellingAnnotation.Count > 0) - //{ - writer.WriteStartArray("modellingAnnotation"u8); - - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modellingAnnotationItem); - } + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -252,117 +204,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); + writer.WriteStartArray("book"u8); - //if (engineeringModel.Book.Count > 0) - //{ - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - //if (engineeringModel.CommonFileStore.Count > 0) - //{ - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModel.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModel.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); - //if (engineeringModel.GenericNote.Count > 0) - //{ - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(genericNoteItem); - } + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - //if (engineeringModel.Iteration.Count > 0) - //{ - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationItem); - } + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (engineeringModel.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); - //if (engineeringModel.ModellingAnnotation.Count > 0) - //{ - writer.WriteStartArray("modellingAnnotation"u8); - - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modellingAnnotationItem); - } + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -373,127 +293,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("book"u8); - if(engineeringModel.Actor.HasValue) - { - writer.WriteStringValue(engineeringModel.Actor.Value); - } - else + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) { - writer.WriteNullValue(); - } - - //if (engineeringModel.Book.Count > 0) - //{ - writer.WriteStartArray("book"u8); - - foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) - { writer.WriteOrderedItem(bookItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); - //if (engineeringModel.CommonFileStore.Count > 0) - //{ - writer.WriteStartArray("commonFileStore"u8); - - foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(commonFileStoreItem); - } + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelSetup"u8); writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModel.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModel.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("genericNote"u8); - //if (engineeringModel.GenericNote.Count > 0) - //{ - writer.WriteStartArray("genericNote"u8); - - foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(genericNoteItem); - } + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); - //if (engineeringModel.Iteration.Count > 0) - //{ - writer.WriteStartArray("iteration"u8); - - foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationItem); - } + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (engineeringModel.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("modellingAnnotation"u8); - //if (engineeringModel.ModellingAnnotation.Count > 0) - //{ - writer.WriteStartArray("modellingAnnotation"u8); - - foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modellingAnnotationItem); - } + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -509,6 +387,118 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EngineeringModel engineeringModel) + { + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -521,32 +511,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "book": - if(!AllowedVersionsPerProperty["book"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -564,11 +548,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -582,11 +561,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "commonfilestore": - if(!AllowedVersionsPerProperty["commonFileStore"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -604,11 +578,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "engineeringmodelsetup": - if(!AllowedVersionsPerProperty["engineeringModelSetup"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("engineeringModelSetup"u8); if(value != null) @@ -622,11 +591,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -644,11 +608,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -666,11 +625,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "genericnote": - if(!AllowedVersionsPerProperty["genericNote"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -688,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -706,11 +655,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iteration": - if(!AllowedVersionsPerProperty["iteration"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -728,11 +672,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "lastmodifiedon": - if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("lastModifiedOn"u8); if(value != null) @@ -746,11 +685,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "logentry": - if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -768,11 +702,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modellingannotation": - if(!AllowedVersionsPerProperty["modellingAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -790,11 +719,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -808,11 +732,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -826,11 +745,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index 517337d6d..64e5c55ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,106 +77,78 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); + writer.WriteStartArray("activeDomain"u8); - //if (engineeringModelSetup.ActiveDomain.Count > 0) - //{ - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); - //if (engineeringModelSetup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (engineeringModelSetup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("hyperLink"u8); - //if (engineeringModelSetup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - //if (engineeringModelSetup.IterationSetup.Count > 0) - //{ - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationSetupItem); - } + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); - //if (engineeringModelSetup.Participant.Count > 0) - //{ - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantItem); - } + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); - //if (engineeringModelSetup.RequiredRdl.Count > 0) - //{ - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requiredRdlItem); - } + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -188,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ShortName); writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } @@ -202,102 +170,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); + writer.WriteStartArray("activeDomain"u8); - //if (engineeringModelSetup.ActiveDomain.Count > 0) - //{ - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); - //if (engineeringModelSetup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (engineeringModelSetup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (engineeringModelSetup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - //if (engineeringModelSetup.IterationSetup.Count > 0) - //{ - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationSetupItem); - } + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -305,31 +245,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); - //if (engineeringModelSetup.Participant.Count > 0) - //{ - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantItem); - } + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); - //if (engineeringModelSetup.RequiredRdl.Count > 0) - //{ - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requiredRdlItem); - } + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -337,7 +269,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ShortName); writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } @@ -351,37 +283,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); + writer.WriteStartArray("activeDomain"u8); - //if (engineeringModelSetup.ActiveDomain.Count > 0) - //{ - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("alias"u8); - //if (engineeringModelSetup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); writer.WritePropertyName("defaultOrganizationalParticipant"u8); - if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) { writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); } @@ -390,73 +314,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (engineeringModelSetup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (engineeringModelSetup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - //if (engineeringModelSetup.IterationSetup.Count > 0) - //{ - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationSetupItem); - } + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -464,44 +369,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); - //if (engineeringModelSetup.OrganizationalParticipant.Count > 0) - //{ - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participant"u8); - //if (engineeringModelSetup.Participant.Count > 0) - //{ - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantItem); - } + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); - //if (engineeringModelSetup.RequiredRdl.Count > 0) - //{ - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requiredRdlItem); - } + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -509,7 +402,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ShortName); writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } @@ -525,47 +418,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); + writer.WriteStartArray("activeDomain"u8); - //if (engineeringModelSetup.ActiveDomain.Count > 0) - //{ - writer.WriteStartArray("activeDomain"u8); - - foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(activeDomainItem); - } + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(engineeringModelSetup.Actor.HasValue) + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(engineeringModelSetup.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (engineeringModelSetup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); writer.WritePropertyName("defaultOrganizationalParticipant"u8); - if(engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) { writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); } @@ -574,73 +449,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (engineeringModelSetup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("engineeringModelIid"u8); writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); - //if (engineeringModelSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (engineeringModelSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (engineeringModelSetup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); - //if (engineeringModelSetup.IterationSetup.Count > 0) - //{ - writer.WriteStartArray("iterationSetup"u8); - - foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(iterationSetupItem); - } + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("kind"u8); writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); @@ -648,44 +504,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); - //if (engineeringModelSetup.OrganizationalParticipant.Count > 0) - //{ - writer.WriteStartArray("organizationalParticipant"u8); - - foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationalParticipantItem); - } + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participant"u8); - //if (engineeringModelSetup.Participant.Count > 0) - //{ - writer.WriteStartArray("participant"u8); - - foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantItem); - } + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requiredRdl"u8); - //if (engineeringModelSetup.RequiredRdl.Count > 0) - //{ - writer.WriteStartArray("requiredRdl"u8); - - foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requiredRdlItem); - } + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); @@ -693,7 +537,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(engineeringModelSetup.ShortName); writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); - if(engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) { writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); } @@ -714,6 +558,165 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -726,14 +729,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + { + return; + } + + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { switch(propertyName.ToLower()) { case "activedomain": - if(!AllowedVersionsPerProperty["activeDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -749,31 +764,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } writer.WriteEndArray(); } - break; - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - break; case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -791,11 +783,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -809,11 +796,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultorganizationalparticipant": - if(!AllowedVersionsPerProperty["defaultOrganizationalParticipant"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultOrganizationalParticipant"u8); if(value != null) @@ -827,11 +809,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -849,11 +826,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "engineeringmodeliid": - if(!AllowedVersionsPerProperty["engineeringModelIid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("engineeringModelIid"u8); if(value != null) @@ -867,11 +839,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -889,11 +856,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -911,11 +873,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -933,11 +890,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -951,11 +903,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iterationsetup": - if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -973,11 +920,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "kind": - if(!AllowedVersionsPerProperty["kind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("kind"u8); if(value != null) @@ -991,11 +933,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1009,11 +946,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -1027,11 +959,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organizationalparticipant": - if(!AllowedVersionsPerProperty["organizationalParticipant"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1049,11 +976,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "participant": - if(!AllowedVersionsPerProperty["participant"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1071,11 +993,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "requiredrdl": - if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1093,11 +1010,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1111,11 +1023,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1129,11 +1036,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceengineeringmodelsetupiid": - if(!AllowedVersionsPerProperty["sourceEngineeringModelSetupIid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); if(value != null) @@ -1147,11 +1049,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "studyphase": - if(!AllowedVersionsPerProperty["studyPhase"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("studyPhase"u8); if(value != null) @@ -1165,11 +1062,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 7ece57e40..4fa334924 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - //if (enumerationParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -149,103 +129,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.ShortName); writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); - //if (enumerationParameterType.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - //if (enumerationParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -261,103 +213,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.ShortName); writer.WritePropertyName("symbol"u8); writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); - //if (enumerationParameterType.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - //if (enumerationParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -375,113 +299,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); - //if (enumerationParameterType.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(enumerationParameterType.Actor.HasValue) - { - writer.WriteStringValue(enumerationParameterType.Actor.Value); - } - else + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (enumerationParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("allowMultiSelect"u8); writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); - //if (enumerationParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationParameterType.Iid); @@ -499,18 +385,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(enumerationParameterType.Symbol); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); - //if (enumerationParameterType.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(valueDefinitionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -520,6 +402,114 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -532,32 +522,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -575,11 +559,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "allowmultiselect": - if(!AllowedVersionsPerProperty["allowMultiSelect"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("allowMultiSelect"u8); if(value != null) @@ -593,11 +572,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -615,11 +589,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -633,11 +602,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -655,11 +619,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -677,11 +636,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -699,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -721,11 +670,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -739,11 +683,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -757,11 +696,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -775,11 +709,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -793,11 +722,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -811,11 +735,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -829,11 +748,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -847,11 +761,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -865,11 +774,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 2bd549351..3806cfcf1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -133,72 +117,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -213,72 +177,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (enumerationValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -295,82 +239,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(enumerationValueDefinition.Actor.HasValue) + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(enumerationValueDefinition.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (enumerationValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (enumerationValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (enumerationValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (enumerationValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (enumerationValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(enumerationValueDefinition.Iid); @@ -392,6 +306,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not EnumerationValueDefinition enumerationValueDefinition) + { + throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -404,32 +400,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -447,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -465,11 +450,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -487,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -509,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -531,11 +501,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -553,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -571,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -589,11 +544,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -607,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -625,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -643,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index 99bac48c6..161c1b59a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -87,49 +83,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (exclusiveOrExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (exclusiveOrExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (exclusiveOrExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -137,49 +121,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (exclusiveOrExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (exclusiveOrExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (exclusiveOrExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -187,62 +159,39 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (exclusiveOrExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(exclusiveOrExpression.Actor.HasValue) - { - writer.WriteStringValue(exclusiveOrExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (exclusiveOrExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (exclusiveOrExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(exclusiveOrExpression.Iid); @@ -250,18 +199,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (exclusiveOrExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(exclusiveOrExpression.ThingPreference); @@ -273,6 +218,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -285,32 +289,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -324,11 +322,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -346,11 +339,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -444,11 +412,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 2c469510a..02ba023de 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,22 +79,18 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); - //if (externalIdentifierMap.Correspondence.Count > 0) - //{ - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalFormat"u8); - if(externalIdentifierMap.ExternalFormat.HasValue) + if (externalIdentifierMap.ExternalFormat.HasValue) { writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); } @@ -126,48 +118,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); - //if (externalIdentifierMap.Correspondence.Count > 0) - //{ - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (externalIdentifierMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (externalIdentifierMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalFormat"u8); - if(externalIdentifierMap.ExternalFormat.HasValue) + if (externalIdentifierMap.ExternalFormat.HasValue) { writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); } @@ -197,48 +177,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); - //if (externalIdentifierMap.Correspondence.Count > 0) - //{ - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (externalIdentifierMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (externalIdentifierMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalFormat"u8); - if(externalIdentifierMap.ExternalFormat.HasValue) + if (externalIdentifierMap.ExternalFormat.HasValue) { writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); } @@ -268,61 +236,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(externalIdentifierMap.Actor.HasValue) - { - writer.WriteStringValue(externalIdentifierMap.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); - //if (externalIdentifierMap.Correspondence.Count > 0) - //{ - writer.WriteStartArray("correspondence"u8); - - foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(correspondenceItem); - } + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (externalIdentifierMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (externalIdentifierMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalFormat"u8); - if(externalIdentifierMap.ExternalFormat.HasValue) + if (externalIdentifierMap.ExternalFormat.HasValue) { writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); } @@ -357,6 +302,86 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -369,32 +394,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -408,11 +427,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "correspondence": - if(!AllowedVersionsPerProperty["correspondence"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -430,11 +444,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -452,11 +461,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -474,11 +478,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "externalformat": - if(!AllowedVersionsPerProperty["externalFormat"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("externalFormat"u8); if(value != null) @@ -492,11 +491,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externalmodelname": - if(!AllowedVersionsPerProperty["externalModelName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("externalModelName"u8); if(value != null) @@ -510,11 +504,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externaltoolname": - if(!AllowedVersionsPerProperty["externalToolName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("externalToolName"u8); if(value != null) @@ -528,11 +517,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "externaltoolversion": - if(!AllowedVersionsPerProperty["externalToolVersion"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("externalToolVersion"u8); if(value != null) @@ -546,11 +530,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -564,11 +543,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -582,11 +556,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -600,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -618,11 +582,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -636,11 +595,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 1a626a01b..944e0e3a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(fileRevision.ContainingFolder.HasValue) + if (fileRevision.ContainingFolder.HasValue) { writer.WriteStringValue(fileRevision.ContainingFolder.Value); } @@ -100,18 +96,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("fileType"u8); - //if (fileRevision.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -126,7 +118,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(fileRevision.ContainingFolder.HasValue) + if (fileRevision.ContainingFolder.HasValue) { writer.WriteStringValue(fileRevision.ContainingFolder.Value); } @@ -141,44 +133,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (fileRevision.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileRevision.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (fileRevision.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -195,7 +175,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(fileRevision.ContainingFolder.HasValue) + if (fileRevision.ContainingFolder.HasValue) { writer.WriteStringValue(fileRevision.ContainingFolder.Value); } @@ -210,44 +190,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (fileRevision.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileRevision.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (fileRevision.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -262,22 +230,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(fileRevision.Actor.HasValue) - { - writer.WriteStringValue(fileRevision.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileRevision.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(fileRevision.ContainingFolder.HasValue) + if (fileRevision.ContainingFolder.HasValue) { writer.WriteStringValue(fileRevision.ContainingFolder.Value); } @@ -292,44 +249,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (fileRevision.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileRevision.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (fileRevision.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(fileTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileRevision.Iid); @@ -349,6 +294,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not FileRevision fileRevision) + { + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -361,32 +384,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -400,11 +417,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containingfolder": - if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("containingFolder"u8); if(value != null) @@ -418,11 +430,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "contenthash": - if(!AllowedVersionsPerProperty["contentHash"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("contentHash"u8); if(value != null) @@ -436,11 +443,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -454,11 +456,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "creator": - if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("creator"u8); if(value != null) @@ -472,11 +469,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -494,11 +486,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -516,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "filetype": - if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -538,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -556,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -574,11 +546,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -592,11 +559,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -610,11 +572,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 6838b588a..785800e6e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,39 +77,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); + writer.WriteStartArray("category"u8); - //if (file.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("fileRevision"u8); - //if (file.FileRevision.Count > 0) - //{ - writer.WriteStartArray("fileRevision"u8); - - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileRevisionItem); - } + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); - if(file.LockedBy.HasValue) + if (file.LockedBy.HasValue) { writer.WriteStringValue(file.LockedBy.Value); } @@ -129,65 +117,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (file.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (file.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (file.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); - //if (file.FileRevision.Count > 0) - //{ - writer.WriteStartArray("fileRevision"u8); - - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileRevisionItem); - } + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); - if(file.LockedBy.HasValue) + if (file.LockedBy.HasValue) { writer.WriteStringValue(file.LockedBy.Value); } @@ -205,65 +177,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (file.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (file.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (file.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); - //if (file.FileRevision.Count > 0) - //{ - writer.WriteStartArray("fileRevision"u8); - - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileRevisionItem); - } + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); - if(file.LockedBy.HasValue) + if (file.LockedBy.HasValue) { writer.WriteStringValue(file.LockedBy.Value); } @@ -283,75 +239,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing File for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(file.Actor.HasValue) + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(file.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - //if (file.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (file.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (file.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileRevision"u8); - //if (file.FileRevision.Count > 0) - //{ - writer.WriteStartArray("fileRevision"u8); - - foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileRevisionItem); - } + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(file.Iid); writer.WritePropertyName("lockedBy"u8); - if(file.LockedBy.HasValue) + if (file.LockedBy.HasValue) { writer.WriteStringValue(file.LockedBy.Value); } @@ -376,6 +306,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not File file) + { + throw new ArgumentException("The thing shall be a File", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -388,32 +399,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -431,11 +436,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -449,11 +449,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -471,11 +466,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -493,11 +483,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "filerevision": - if(!AllowedVersionsPerProperty["fileRevision"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +500,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -533,11 +513,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "lockedby": - if(!AllowedVersionsPerProperty["lockedBy"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("lockedBy"u8); if(value != null) @@ -551,11 +526,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -569,11 +539,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -587,11 +552,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -605,11 +565,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 9399482a6..d1366a4ad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (fileType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (fileType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (fileType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - //if (fileType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -150,87 +130,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (fileType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (fileType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (fileType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (fileType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - //if (fileType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -247,87 +203,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (fileType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (fileType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (fileType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (fileType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - //if (fileType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -346,97 +278,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(fileType.Actor.HasValue) + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(fileType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (fileType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (fileType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (fileType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (fileType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (fileType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("extension"u8); writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); - //if (fileType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(fileType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not FileType fileType) + { + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "extension": - if(!AllowedVersionsPerProperty["extension"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("extension"u8); if(value != null) @@ -639,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 77764572a..946cc3bc5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(folder.ContainingFolder.HasValue) + if (folder.ContainingFolder.HasValue) { writer.WriteStringValue(folder.ContainingFolder.Value); } @@ -113,7 +109,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(folder.ContainingFolder.HasValue) + if (folder.ContainingFolder.HasValue) { writer.WriteStringValue(folder.ContainingFolder.Value); } @@ -126,31 +122,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (folder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (folder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -169,7 +157,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(folder.ContainingFolder.HasValue) + if (folder.ContainingFolder.HasValue) { writer.WriteStringValue(folder.ContainingFolder.Value); } @@ -182,31 +170,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (folder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (folder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -223,22 +203,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(folder.Actor.HasValue) - { - writer.WriteStringValue(folder.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(folder.ClassKind.ToString()); writer.WritePropertyName("containingFolder"u8); - if(folder.ContainingFolder.HasValue) + if (folder.ContainingFolder.HasValue) { writer.WriteStringValue(folder.ContainingFolder.Value); } @@ -251,31 +220,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("creator"u8); writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); - //if (folder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (folder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(folder.Iid); @@ -297,6 +258,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Folder folder) + { + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -309,32 +338,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -348,11 +371,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containingfolder": - if(!AllowedVersionsPerProperty["containingFolder"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("containingFolder"u8); if(value != null) @@ -366,11 +384,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -384,11 +397,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "creator": - if(!AllowedVersionsPerProperty["creator"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("creator"u8); if(value != null) @@ -402,11 +410,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -424,11 +427,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -446,11 +444,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -464,11 +457,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -482,11 +470,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -500,11 +483,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -518,11 +496,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -536,11 +509,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index 7883f9294..efebbeaf7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (glossary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (glossary.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (glossary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (glossary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -145,101 +125,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - //if (glossary.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (glossary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (glossary.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (glossary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (glossary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (glossary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (glossary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -253,101 +205,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - //if (glossary.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (glossary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (glossary.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (glossary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (glossary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (glossary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (glossary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -361,113 +285,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - //if (glossary.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(glossary.Actor.HasValue) + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(glossary.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (glossary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (glossary.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (glossary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (glossary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (glossary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (glossary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(glossary.Iid); @@ -481,18 +367,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(glossary.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); - //if (glossary.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(glossary.ThingPreference); @@ -504,6 +386,110 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Glossary glossary) + { + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -516,32 +502,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -559,11 +539,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -581,11 +556,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -599,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +586,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +603,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -665,11 +620,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -687,11 +637,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -705,11 +650,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -723,11 +663,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -741,11 +676,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -759,11 +689,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -777,11 +702,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -795,11 +715,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -817,11 +732,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index a8ba8576d..daa91005a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,85 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (goal.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (goal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (goal.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (goal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (goal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (goal.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -174,85 +146,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (goal.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (goal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (goal.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (goal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (goal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (goal.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -269,95 +217,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(goal.Actor.HasValue) - { - writer.WriteStringValue(goal.Actor.Value); - } - else + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (goal.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (goal.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (goal.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (goal.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (goal.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (goal.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(goal.Iid); @@ -379,6 +293,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -391,32 +397,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -434,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -456,11 +451,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -474,11 +464,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -496,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -518,11 +498,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -540,11 +515,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -562,11 +532,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -580,11 +545,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -598,11 +558,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -616,11 +571,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -634,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -652,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 28c2c3100..80f1f4e67 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -100,31 +96,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (hyperLink.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (hyperLink.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -143,31 +131,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (hyperLink.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (hyperLink.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -184,46 +164,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(hyperLink.Actor.HasValue) - { - writer.WriteStringValue(hyperLink.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(hyperLink.ClassKind.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); - //if (hyperLink.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (hyperLink.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(hyperLink.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,32 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -296,11 +306,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -314,11 +319,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -336,11 +336,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "uri": - if(!AllowedVersionsPerProperty["uri"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("uri"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index b97a71551..fd465e905 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (idCorrespondence.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (idCorrespondence.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (idCorrespondence.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (idCorrespondence.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(idCorrespondence.Actor.HasValue) - { - writer.WriteStringValue(idCorrespondence.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (idCorrespondence.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (idCorrespondence.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("externalId"u8); writer.WriteStringValue(idCorrespondence.ExternalId); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not IdCorrespondence idCorrespondence) + { + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "externalid": - if(!AllowedVersionsPerProperty["externalId"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("externalId"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "internalthing": - if(!AllowedVersionsPerProperty["internalThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("internalThing"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index ab578f69f..d7858bb30 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,37 +79,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); writer.WritePropertyName("measurementScale"u8); - if(independentParameterTypeAssignment.MeasurementScale.HasValue) + if (independentParameterTypeAssignment.MeasurementScale.HasValue) { writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); } @@ -133,50 +121,31 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(independentParameterTypeAssignment.Actor.HasValue) - { - writer.WriteStringValue(independentParameterTypeAssignment.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (independentParameterTypeAssignment.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (independentParameterTypeAssignment.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(independentParameterTypeAssignment.Iid); writer.WritePropertyName("measurementScale"u8); - if(independentParameterTypeAssignment.MeasurementScale.HasValue) + if (independentParameterTypeAssignment.MeasurementScale.HasValue) { writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); } @@ -201,6 +170,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -213,32 +244,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -252,11 +277,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -274,11 +294,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -296,11 +311,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -314,11 +324,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "measurementscale": - if(!AllowedVersionsPerProperty["measurementScale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("measurementScale"u8); if(value != null) @@ -332,11 +337,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -350,11 +350,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -368,11 +363,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -386,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 6df6984b4..00cf3a169 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (intervalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (intervalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (intervalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (intervalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -161,88 +141,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (intervalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (intervalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (intervalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (intervalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (intervalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (intervalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -252,18 +208,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (intervalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -285,88 +237,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (intervalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (intervalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (intervalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (intervalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (intervalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (intervalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -376,18 +304,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (intervalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -411,98 +335,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (intervalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(intervalScale.Actor.HasValue) - { - writer.WriteStringValue(intervalScale.Actor.Value); - } - else + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (intervalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (intervalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (intervalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (intervalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (intervalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(intervalScale.Iid); @@ -512,18 +402,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (intervalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(intervalScale.MaximumPermissibleValue); @@ -547,18 +433,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(intervalScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (intervalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -568,6 +450,126 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not IntervalScale intervalScale) + { + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -580,32 +582,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -623,11 +619,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -641,11 +632,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -663,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -685,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +683,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -729,11 +700,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -747,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -765,11 +726,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ismaximuminclusive": - if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) @@ -783,11 +739,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isminimuminclusive": - if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) @@ -801,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mappingtoreferencescale": - if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -823,11 +769,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "maximumpermissiblevalue": - if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) @@ -841,11 +782,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minimumpermissiblevalue": - if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minimumPermissibleValue"u8); if(value != null) @@ -859,11 +795,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -877,11 +808,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -895,11 +821,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("negativeValueConnotation"u8); if(value != null) @@ -913,11 +834,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("numberSet"u8); if(value != null) @@ -931,11 +847,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("positiveValueConnotation"u8); if(value != null) @@ -949,11 +860,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -967,11 +873,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -985,11 +886,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1003,11 +899,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) @@ -1021,11 +912,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index 5f192e057..f56e22d25 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,24 +77,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - //if (iteration.ActualFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("actualFiniteStateList"u8); - - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualFiniteStateListItem); - } + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); writer.WritePropertyName("defaultOption"u8); - if(iteration.DefaultOption.HasValue) + if (iteration.DefaultOption.HasValue) { writer.WriteStringValue(iteration.DefaultOption.Value); } @@ -107,131 +99,96 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.DomainFileStore.Count > 0) - //{ - writer.WriteStartArray("domainFileStore"u8); + writer.WriteStartArray("domainFileStore"u8); - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainFileStoreItem); - } + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); - //if (iteration.Element.Count > 0) - //{ - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(elementItem); - } + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); - //if (iteration.ExternalIdentifierMap.Count > 0) - //{ - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(externalIdentifierMapItem); - } + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); writer.WritePropertyName("iterationSetup"u8); writer.WriteStringValue(iteration.IterationSetup); + writer.WriteStartArray("option"u8); - //if (iteration.Option.Count > 0) - //{ - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (iteration.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleFiniteStateListItem); - } + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); - //if (iteration.Publication.Count > 0) - //{ - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publicationItem); - } + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); - //if (iteration.Relationship.Count > 0) - //{ - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relationshipItem); - } + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); - //if (iteration.RequirementsSpecification.Count > 0) - //{ - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementsSpecificationItem); - } + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - //if (iteration.RuleVerificationList.Count > 0) - //{ - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleVerificationListItem); - } + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("sourceIterationIid"u8); - if(iteration.SourceIterationIid.HasValue) + if (iteration.SourceIterationIid.HasValue) { writer.WriteStringValue(iteration.SourceIterationIid.Value); } @@ -242,7 +199,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("topElement"u8); - if(iteration.TopElement.HasValue) + if (iteration.TopElement.HasValue) { writer.WriteStringValue(iteration.TopElement.Value); } @@ -254,24 +211,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - //if (iteration.ActualFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("actualFiniteStateList"u8); - - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualFiniteStateListItem); - } + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); writer.WritePropertyName("defaultOption"u8); - if(iteration.DefaultOption.HasValue) + if (iteration.DefaultOption.HasValue) { writer.WriteStringValue(iteration.DefaultOption.Value); } @@ -280,95 +233,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.DiagramCanvas.Count > 0) - //{ - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteStartArray("diagramCanvas"u8); - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramCanvasItem); - } + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); - //if (iteration.DomainFileStore.Count > 0) - //{ - writer.WriteStartArray("domainFileStore"u8); - - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainFileStoreItem); - } + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); - //if (iteration.Element.Count > 0) - //{ - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(elementItem); - } + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (iteration.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iteration.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); - //if (iteration.ExternalIdentifierMap.Count > 0) - //{ - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(externalIdentifierMapItem); - } + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (iteration.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -376,102 +302,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); - //if (iteration.Option.Count > 0) - //{ - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (iteration.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleFiniteStateListItem); - } + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); - //if (iteration.Publication.Count > 0) - //{ - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publicationItem); - } + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); - //if (iteration.Relationship.Count > 0) - //{ - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relationshipItem); - } + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); - //if (iteration.RequirementsSpecification.Count > 0) - //{ - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementsSpecificationItem); - } + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - //if (iteration.RuleVerificationList.Count > 0) - //{ - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleVerificationListItem); - } + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); - //if (iteration.SharedDiagramStyle.Count > 0) - //{ - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sharedDiagramStyleItem); - } + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("sourceIterationIid"u8); - if(iteration.SourceIterationIid.HasValue) + if (iteration.SourceIterationIid.HasValue) { writer.WriteStringValue(iteration.SourceIterationIid.Value); } @@ -480,47 +378,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.Stakeholder.Count > 0) - //{ - writer.WriteStartArray("stakeholder"u8); + writer.WriteStartArray("stakeholder"u8); - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); - //if (iteration.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); - //if (iteration.StakeholderValueMap.Count > 0) - //{ - writer.WriteStartArray("stakeholderValueMap"u8); - - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueMapItem); - } + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("topElement"u8); - if(iteration.TopElement.HasValue) + if (iteration.TopElement.HasValue) { writer.WriteStringValue(iteration.TopElement.Value); } @@ -529,39 +416,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); + writer.WriteStartArray("actualFiniteStateList"u8); - //if (iteration.ActualFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("actualFiniteStateList"u8); - - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualFiniteStateListItem); - } + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); writer.WritePropertyName("defaultOption"u8); - if(iteration.DefaultOption.HasValue) + if (iteration.DefaultOption.HasValue) { writer.WriteStringValue(iteration.DefaultOption.Value); } @@ -570,95 +450,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.DiagramCanvas.Count > 0) - //{ - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteStartArray("diagramCanvas"u8); - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramCanvasItem); - } + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); - //if (iteration.DomainFileStore.Count > 0) - //{ - writer.WriteStartArray("domainFileStore"u8); - - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainFileStoreItem); - } + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); - //if (iteration.Element.Count > 0) - //{ - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(elementItem); - } + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (iteration.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iteration.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); - //if (iteration.ExternalIdentifierMap.Count > 0) - //{ - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(externalIdentifierMapItem); - } + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (iteration.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -666,102 +519,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); - //if (iteration.Option.Count > 0) - //{ - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (iteration.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleFiniteStateListItem); - } + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); - //if (iteration.Publication.Count > 0) - //{ - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publicationItem); - } + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); - //if (iteration.Relationship.Count > 0) - //{ - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relationshipItem); - } + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirementsSpecification"u8); - //if (iteration.RequirementsSpecification.Count > 0) - //{ - writer.WriteStartArray("requirementsSpecification"u8); - - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementsSpecificationItem); - } + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - //if (iteration.RuleVerificationList.Count > 0) - //{ - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleVerificationListItem); - } + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); - //if (iteration.SharedDiagramStyle.Count > 0) - //{ - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sharedDiagramStyleItem); - } + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("sourceIterationIid"u8); - if(iteration.SourceIterationIid.HasValue) + if (iteration.SourceIterationIid.HasValue) { writer.WriteStringValue(iteration.SourceIterationIid.Value); } @@ -770,49 +595,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.Stakeholder.Count > 0) - //{ - writer.WriteStartArray("stakeholder"u8); + writer.WriteStartArray("stakeholder"u8); - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); - //if (iteration.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); - //if (iteration.StakeholderValueMap.Count > 0) - //{ - writer.WriteStartArray("stakeholderValueMap"u8); - - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueMapItem); - } + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); writer.WritePropertyName("topElement"u8); - if(iteration.TopElement.HasValue) + if (iteration.TopElement.HasValue) { writer.WriteStringValue(iteration.TopElement.Value); } @@ -821,49 +635,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("actualFiniteStateList"u8); - if(iteration.Actor.HasValue) + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(iteration.Actor.Value); + writer.WriteStringValue(actualFiniteStateListItem); } - else - { - writer.WriteNullValue(); - } - - //if (iteration.ActualFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("actualFiniteStateList"u8); - foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(actualFiniteStateListItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iteration.ClassKind.ToString()); writer.WritePropertyName("defaultOption"u8); - if(iteration.DefaultOption.HasValue) + if (iteration.DefaultOption.HasValue) { writer.WriteStringValue(iteration.DefaultOption.Value); } @@ -872,95 +669,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.DiagramCanvas.Count > 0) - //{ - writer.WriteStartArray("diagramCanvas"u8); + writer.WriteStartArray("diagramCanvas"u8); - foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(diagramCanvasItem); - } + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainFileStore"u8); - //if (iteration.DomainFileStore.Count > 0) - //{ - writer.WriteStartArray("domainFileStore"u8); - - foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainFileStoreItem); - } + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("element"u8); - //if (iteration.Element.Count > 0) - //{ - writer.WriteStartArray("element"u8); - - foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(elementItem); - } + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (iteration.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iteration.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("externalIdentifierMap"u8); - //if (iteration.ExternalIdentifierMap.Count > 0) - //{ - writer.WriteStartArray("externalIdentifierMap"u8); - - foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(externalIdentifierMapItem); - } + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (iteration.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(iteration.Iid); @@ -968,102 +738,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iteration.IterationSetup); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); - //if (iteration.Option.Count > 0) - //{ - writer.WriteStartArray("option"u8); - - foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(optionItem); - } - - writer.WriteEndArray(); - //} - - - //if (iteration.PossibleFiniteStateList.Count > 0) - //{ - writer.WriteStartArray("possibleFiniteStateList"u8); - - foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleFiniteStateListItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("possibleFiniteStateList"u8); - //if (iteration.Publication.Count > 0) - //{ - writer.WriteStartArray("publication"u8); - - foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publicationItem); - } + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("publication"u8); - //if (iteration.Relationship.Count > 0) - //{ - writer.WriteStartArray("relationship"u8); - - foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relationshipItem); - } + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relationship"u8); - //if (iteration.RequirementsSpecification.Count > 0) - //{ - writer.WriteStartArray("requirementsSpecification"u8); + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } - foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementsSpecificationItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); - writer.WriteEndArray(); - //} + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); - //if (iteration.RuleVerificationList.Count > 0) - //{ - writer.WriteStartArray("ruleVerificationList"u8); - - foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleVerificationListItem); - } + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sharedDiagramStyle"u8); - //if (iteration.SharedDiagramStyle.Count > 0) - //{ - writer.WriteStartArray("sharedDiagramStyle"u8); - - foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sharedDiagramStyleItem); - } + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("sourceIterationIid"u8); - if(iteration.SourceIterationIid.HasValue) + if (iteration.SourceIterationIid.HasValue) { writer.WriteStringValue(iteration.SourceIterationIid.Value); } @@ -1072,49 +814,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.Stakeholder.Count > 0) - //{ - writer.WriteStartArray("stakeholder"u8); + writer.WriteStartArray("stakeholder"u8); - foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderItem); - } + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValue"u8); - //if (iteration.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("stakeholderValueMap"u8); - //if (iteration.StakeholderValueMap.Count > 0) - //{ - writer.WriteStartArray("stakeholderValueMap"u8); - - foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueMapItem); - } + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(iteration.ThingPreference); writer.WritePropertyName("topElement"u8); - if(iteration.TopElement.HasValue) + if (iteration.TopElement.HasValue) { writer.WriteStringValue(iteration.TopElement.Value); } @@ -1123,17 +854,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (iteration.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); + writer.WriteStartArray("valueGroup"u8); - foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -1143,6 +871,256 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Iteration iteration) + { + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -1155,32 +1133,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "actualfinitestatelist": - if(!AllowedVersionsPerProperty["actualFiniteStateList"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1198,11 +1170,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -1216,11 +1183,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultoption": - if(!AllowedVersionsPerProperty["defaultOption"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultOption"u8); if(value != null) @@ -1234,11 +1196,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "diagramcanvas": - if(!AllowedVersionsPerProperty["diagramCanvas"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1256,11 +1213,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "domainfilestore": - if(!AllowedVersionsPerProperty["domainFileStore"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1278,11 +1230,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "element": - if(!AllowedVersionsPerProperty["element"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1300,11 +1247,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1322,11 +1264,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1344,11 +1281,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "externalidentifiermap": - if(!AllowedVersionsPerProperty["externalIdentifierMap"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1366,11 +1298,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "goal": - if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1388,11 +1315,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -1406,11 +1328,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iterationsetup": - if(!AllowedVersionsPerProperty["iterationSetup"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iterationSetup"u8); if(value != null) @@ -1424,11 +1341,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1442,11 +1354,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "option": - if(!AllowedVersionsPerProperty["option"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1464,11 +1371,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "possiblefinitestatelist": - if(!AllowedVersionsPerProperty["possibleFiniteStateList"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1486,11 +1388,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "publication": - if(!AllowedVersionsPerProperty["publication"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1508,11 +1405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "relationship": - if(!AllowedVersionsPerProperty["relationship"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1530,11 +1422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "requirementsspecification": - if(!AllowedVersionsPerProperty["requirementsSpecification"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1552,11 +1439,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1570,11 +1452,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ruleverificationlist": - if(!AllowedVersionsPerProperty["ruleVerificationList"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1592,11 +1469,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shareddiagramstyle": - if(!AllowedVersionsPerProperty["sharedDiagramStyle"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1614,11 +1486,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "sourceiterationiid": - if(!AllowedVersionsPerProperty["sourceIterationIid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sourceIterationIid"u8); if(value != null) @@ -1632,11 +1499,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "stakeholder": - if(!AllowedVersionsPerProperty["stakeholder"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1654,11 +1516,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "stakeholdervalue": - if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1676,11 +1533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "stakeholdervaluemap": - if(!AllowedVersionsPerProperty["stakeholderValueMap"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1698,11 +1550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1716,11 +1563,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "topelement": - if(!AllowedVersionsPerProperty["topElement"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("topElement"u8); if(value != null) @@ -1734,11 +1576,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuegroup": - if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index b3666c02a..562b4235b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,7 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.Description); writer.WritePropertyName("frozenOn"u8); - if(iterationSetup.FrozenOn.HasValue) + if (iterationSetup.FrozenOn.HasValue) { writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -110,7 +106,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(iterationSetup.RevisionNumber); writer.WritePropertyName("sourceIterationSetup"u8); - if(iterationSetup.SourceIterationSetup.HasValue) + if (iterationSetup.SourceIterationSetup.HasValue) { writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } @@ -128,35 +124,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (iterationSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iterationSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("frozenOn"u8); - if(iterationSetup.FrozenOn.HasValue) + if (iterationSetup.FrozenOn.HasValue) { writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -179,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(iterationSetup.RevisionNumber); writer.WritePropertyName("sourceIterationSetup"u8); - if(iterationSetup.SourceIterationSetup.HasValue) + if (iterationSetup.SourceIterationSetup.HasValue) { writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } @@ -197,35 +185,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (iterationSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iterationSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("frozenOn"u8); - if(iterationSetup.FrozenOn.HasValue) + if (iterationSetup.FrozenOn.HasValue) { writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -248,7 +228,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(iterationSetup.RevisionNumber); writer.WritePropertyName("sourceIterationSetup"u8); - if(iterationSetup.SourceIterationSetup.HasValue) + if (iterationSetup.SourceIterationSetup.HasValue) { writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } @@ -262,52 +242,33 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(iterationSetup.Actor.HasValue) - { - writer.WriteStringValue(iterationSetup.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(iterationSetup.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("description"u8); writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (iterationSetup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (iterationSetup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("frozenOn"u8); - if(iterationSetup.FrozenOn.HasValue) + if (iterationSetup.FrozenOn.HasValue) { writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -330,7 +291,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(iterationSetup.RevisionNumber); writer.WritePropertyName("sourceIterationSetup"u8); - if(iterationSetup.SourceIterationSetup.HasValue) + if (iterationSetup.SourceIterationSetup.HasValue) { writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); } @@ -349,6 +310,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -361,32 +403,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -400,11 +436,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -418,11 +449,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "description": - if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("description"u8); if(value != null) @@ -436,11 +462,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -458,11 +479,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -480,11 +496,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "frozenon": - if(!AllowedVersionsPerProperty["frozenOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("frozenOn"u8); if(value != null) @@ -498,11 +509,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -516,11 +522,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeleted": - if(!AllowedVersionsPerProperty["isDeleted"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeleted"u8); if(value != null) @@ -534,11 +535,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iterationiid": - if(!AllowedVersionsPerProperty["iterationIid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iterationIid"u8); if(value != null) @@ -552,11 +548,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iterationnumber": - if(!AllowedVersionsPerProperty["iterationNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iterationNumber"u8); if(value != null) @@ -570,11 +561,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -588,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -606,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceiterationsetup": - if(!AllowedVersionsPerProperty["sourceIterationSetup"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("sourceIterationSetup"u8); if(value != null) @@ -624,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 5a131068e..1e16a3a6c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (linearConversionUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (linearConversionUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (linearConversionUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -139,74 +123,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (linearConversionUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (linearConversionUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (linearConversionUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (linearConversionUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (linearConversionUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -225,74 +189,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (linearConversionUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (linearConversionUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (linearConversionUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (linearConversionUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (linearConversionUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -313,84 +257,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(linearConversionUnit.Actor.HasValue) - { - writer.WriteStringValue(linearConversionUnit.Actor.Value); - } - else + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (linearConversionUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (linearConversionUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (linearConversionUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (linearConversionUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (linearConversionUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(linearConversionUnit.Iid); @@ -416,6 +330,94 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not LinearConversionUnit linearConversionUnit) + { + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -428,32 +430,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -471,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -489,11 +480,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "conversionfactor": - if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("conversionFactor"u8); if(value != null) @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -529,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +527,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -573,11 +544,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -595,11 +561,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -631,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -649,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -667,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referenceunit": - if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referenceUnit"u8); if(value != null) @@ -685,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -703,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -721,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index 2cbd22482..c55d29bde 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,18 +79,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.2.0"); writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); - //if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) - //{ - writer.WriteStartArray("affectedReferenceIid"u8); - - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) - { - writer.WriteStringValue(affectedReferenceIidItem); - } + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -102,31 +94,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (logEntryChangelogItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (logEntryChangelogItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -139,31 +123,16 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(logEntryChangelogItem.Actor.HasValue) - { - writer.WriteStringValue(logEntryChangelogItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("affectedItemIid"u8); writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); - //if (logEntryChangelogItem.AffectedReferenceIid.Count > 0) - //{ - writer.WriteStartArray("affectedReferenceIid"u8); - - foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) - { - writer.WriteStringValue(affectedReferenceIidItem); - } + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("changeDescription"u8); writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); @@ -171,31 +140,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (logEntryChangelogItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (logEntryChangelogItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logEntryChangelogItem.Iid); @@ -213,6 +174,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not LogEntryChangelogItem logEntryChangelogItem) + { + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -225,32 +251,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "affecteditemiid": - if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("affectedItemIid"u8); if(value != null) @@ -264,11 +284,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "affectedreferenceiid": - if(!AllowedVersionsPerProperty["affectedReferenceIid"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -286,11 +301,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "changedescription": - if(!AllowedVersionsPerProperty["changeDescription"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("changeDescription"u8); if(value != null) @@ -304,11 +314,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "changelogkind": - if(!AllowedVersionsPerProperty["changelogKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("changelogKind"u8); if(value != null) @@ -322,11 +327,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -340,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -362,11 +357,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -384,11 +374,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -402,11 +387,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -420,11 +400,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -438,11 +413,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index e30c06dfb..f70c4e21d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,50 +77,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (logarithmicScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (logarithmicScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - //if (logarithmicScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -136,18 +120,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (logarithmicScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -163,18 +143,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - //if (logarithmicScale.ReferenceQuantityValue.Count > 0) - //{ - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -182,92 +158,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (logarithmicScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (logarithmicScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (logarithmicScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (logarithmicScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (logarithmicScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - //if (logarithmicScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -279,18 +231,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (logarithmicScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -308,18 +256,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - //if (logarithmicScale.ReferenceQuantityValue.Count > 0) - //{ - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -327,92 +271,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (logarithmicScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (logarithmicScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (logarithmicScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (logarithmicScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (logarithmicScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - //if (logarithmicScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -424,18 +344,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (logarithmicScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -453,18 +369,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - //if (logarithmicScale.ReferenceQuantityValue.Count > 0) - //{ - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -474,102 +386,68 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (logarithmicScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(logarithmicScale.Actor.HasValue) - { - writer.WriteStringValue(logarithmicScale.Actor.Value); - } - else + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (logarithmicScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (logarithmicScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (logarithmicScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (logarithmicScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(logarithmicScale.Exponent); writer.WritePropertyName("factor"u8); writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); - //if (logarithmicScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(logarithmicScale.Iid); @@ -581,18 +459,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); writer.WritePropertyName("logarithmBase"u8); writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (logarithmicScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); @@ -610,18 +484,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); writer.WritePropertyName("referenceQuantityKind"u8); writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); - //if (logarithmicScale.ReferenceQuantityValue.Count > 0) - //{ - writer.WriteStartArray("referenceQuantityValue"u8); - - foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceQuantityValueItem); - } + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(logarithmicScale.RevisionNumber); @@ -631,18 +501,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(logarithmicScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (logarithmicScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -652,6 +518,144 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -664,32 +668,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +705,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -725,11 +718,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -747,11 +735,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -769,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -791,11 +769,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "exponent": - if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("exponent"u8); if(value != null) @@ -809,11 +782,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "factor": - if(!AllowedVersionsPerProperty["factor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("factor"u8); if(value != null) @@ -827,11 +795,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -849,11 +812,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -867,11 +825,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -885,11 +838,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ismaximuminclusive": - if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) @@ -903,11 +851,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isminimuminclusive": - if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) @@ -921,11 +864,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "logarithmbase": - if(!AllowedVersionsPerProperty["logarithmBase"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("logarithmBase"u8); if(value != null) @@ -939,11 +877,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mappingtoreferencescale": - if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -961,11 +894,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "maximumpermissiblevalue": - if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) @@ -979,11 +907,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minimumpermissiblevalue": - if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minimumPermissibleValue"u8); if(value != null) @@ -997,11 +920,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1015,11 +933,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -1033,11 +946,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("negativeValueConnotation"u8); if(value != null) @@ -1051,11 +959,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("numberSet"u8); if(value != null) @@ -1069,11 +972,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("positiveValueConnotation"u8); if(value != null) @@ -1087,11 +985,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencequantitykind": - if(!AllowedVersionsPerProperty["referenceQuantityKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referenceQuantityKind"u8); if(value != null) @@ -1105,11 +998,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencequantityvalue": - if(!AllowedVersionsPerProperty["referenceQuantityValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1127,11 +1015,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1145,11 +1028,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1163,11 +1041,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1181,11 +1054,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) @@ -1199,11 +1067,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index b37cb3c78..40973d997 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -98,31 +94,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); - //if (mappingToReferenceScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (mappingToReferenceScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -139,31 +127,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); - //if (mappingToReferenceScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (mappingToReferenceScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -178,46 +158,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(mappingToReferenceScale.Actor.HasValue) - { - writer.WriteStringValue(mappingToReferenceScale.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); writer.WritePropertyName("dependentScaleValue"u8); writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); - //if (mappingToReferenceScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (mappingToReferenceScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(mappingToReferenceScale.Iid); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not MappingToReferenceScale mappingToReferenceScale) + { + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "dependentscalevalue": - if(!AllowedVersionsPerProperty["dependentScaleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("dependentScaleValue"u8); if(value != null) @@ -306,11 +309,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -328,11 +326,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencescalevalue": - if(!AllowedVersionsPerProperty["referenceScaleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referenceScaleValue"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index cfa0532fa..bf94029c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,35 +77,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (modelLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (modelLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(modelLogEntry.Author.HasValue) + if (modelLogEntry.Author.HasValue) { writer.WriteStringValue(modelLogEntry.Author.Value); } @@ -118,17 +106,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (modelLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -147,35 +132,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (modelLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (modelLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(modelLogEntry.Author.HasValue) + if (modelLogEntry.Author.HasValue) { writer.WriteStringValue(modelLogEntry.Author.Value); } @@ -184,17 +161,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (modelLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -202,31 +176,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (modelLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modelLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -241,35 +207,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (modelLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (modelLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(modelLogEntry.Author.HasValue) + if (modelLogEntry.Author.HasValue) { writer.WriteStringValue(modelLogEntry.Author.Value); } @@ -278,17 +236,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (modelLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -296,31 +251,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (modelLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modelLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -328,18 +275,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - //if (modelLogEntry.LogEntryChangelogItem.Count > 0) - //{ - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryChangelogItemItem); - } + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -350,45 +293,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("affectedDomainIid"u8); - if(modelLogEntry.Actor.HasValue) + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) { - writer.WriteStringValue(modelLogEntry.Actor.Value); + writer.WriteStringValue(affectedDomainIidItem); } - else - { - writer.WriteNullValue(); - } - - //if (modelLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (modelLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(modelLogEntry.Author.HasValue) + if (modelLogEntry.Author.HasValue) { writer.WriteStringValue(modelLogEntry.Author.Value); } @@ -397,17 +322,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (modelLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); @@ -415,31 +337,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (modelLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modelLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelLogEntry.Iid); @@ -447,18 +361,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - //if (modelLogEntry.LogEntryChangelogItem.Count > 0) - //{ - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryChangelogItemItem); - } + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -474,6 +384,112 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -486,32 +502,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "affecteddomainiid": - if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -529,11 +539,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "affecteditemiid": - if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +556,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -569,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +586,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -609,11 +599,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -627,11 +612,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -645,11 +625,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -667,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -689,11 +659,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -707,11 +672,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -725,11 +685,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "level": - if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("level"u8); if(value != null) @@ -743,11 +698,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "logentrychangelogitem": - if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -765,11 +715,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -783,11 +728,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -801,11 +741,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 0117f8784..5dfeb2199 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,158 +77,114 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (modelReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (modelReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (modelReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (modelReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (modelReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (modelReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (modelReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (modelReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(modelReferenceDataLibrary.RequiredRdl.HasValue) + if (modelReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); } @@ -243,207 +195,147 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (modelReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (modelReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - //if (modelReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (modelReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (modelReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (modelReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (modelReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (modelReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (modelReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (modelReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -451,35 +343,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (modelReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(modelReferenceDataLibrary.RequiredRdl.HasValue) + if (modelReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); } @@ -490,207 +374,328 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (modelReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (modelReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - //if (modelReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (modelReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (modelReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (modelReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); - writer.WriteEndArray(); - //} + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); - writer.WriteEndArray(); - //} + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modelReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); - writer.WriteEndArray(); - //} + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); - //} + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); - writer.WriteEndArray(); - //} + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + writer.WritePropertyName("requiredRdl"u8); - //if (modelReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - writer.WriteEndArray(); - //} + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (modelReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); - writer.WriteEndArray(); - //} + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (modelReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); + writer.WriteStartArray("alias"u8); - writer.WriteEndArray(); - //} + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modelReferenceDataLibrary.Iid); @@ -698,35 +703,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (modelReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(modelReferenceDataLibrary.RequiredRdl.HasValue) + if (modelReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); } @@ -737,325 +734,263 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (modelReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (modelReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(modelReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); - //if (modelReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; - case "1.3.0": - Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); + } + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } - if(modelReferenceDataLibrary.Actor.HasValue) - { - writer.WriteStringValue(modelReferenceDataLibrary.Actor.Value); - } - else - { - writer.WriteNullValue(); - } + writer.WriteStartObject(); - //if (modelReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); + writer.WriteStartArray("alias"u8); - foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); + writer.WriteStartArray("baseQuantityKind"u8); - foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { - writer.WriteOrderedItem(baseQuantityKindItem); - } + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); + writer.WriteStartArray("baseUnit"u8); - foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} - - writer.WritePropertyName("classKind"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); - //if (modelReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); + writer.WriteStartArray("constant"u8); - foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); + writer.WriteStartArray("definedCategory"u8); - foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); + writer.WriteStartArray("excludedPerson"u8); - foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); + writer.WriteStartArray("fileType"u8); - foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); + writer.WriteStartArray("glossary"u8); - foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} - - writer.WritePropertyName("iid"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Iid); - writer.WritePropertyName("modifiedOn"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); - writer.WritePropertyName("name"u8); - writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); - //if (modelReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); + writer.WriteStartArray("parameterType"u8); - foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); + writer.WriteStartArray("referenceSource"u8); - foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} - - writer.WritePropertyName("requiredRdl"u8); + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); - if(modelReferenceDataLibrary.RequiredRdl.HasValue) - { - writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); - } - else - { - writer.WriteNullValue(); - } + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } - writer.WritePropertyName("revisionNumber"u8); - writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); - //if (modelReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); + writer.WriteStartArray("rule"u8); - foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); + writer.WriteStartArray("scale"u8); - foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} - - writer.WritePropertyName("shortName"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ShortName); - writer.WritePropertyName("thingPreference"u8); - writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); - //if (modelReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); + writer.WriteStartArray("unit"u8); - foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} - + writer.WriteEndArray(); + - //if (modelReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); + writer.WriteStartArray("unitPrefix"u8); - foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} - - break; - default: - throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); - } + writer.WriteEndArray(); + writer.WriteEndObject(); } @@ -1072,32 +1007,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1115,11 +1044,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "basequantitykind": - if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1137,11 +1061,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "baseunit": - if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1159,11 +1078,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -1177,11 +1091,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "constant": - if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1199,11 +1108,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definedcategory": - if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1221,11 +1125,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1243,11 +1142,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1265,11 +1159,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1287,11 +1176,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "filetype": - if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1309,11 +1193,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "glossary": - if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1331,11 +1210,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1353,11 +1227,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -1371,11 +1240,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1389,11 +1253,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -1407,11 +1266,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1429,11 +1283,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "referencesource": - if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1451,11 +1300,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "requiredrdl": - if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("requiredRdl"u8); if(value != null) @@ -1469,11 +1313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1487,11 +1326,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rule": - if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1509,11 +1343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1531,11 +1360,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1549,11 +1373,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1567,11 +1386,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1589,11 +1403,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "unitprefix": - if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 58ea710d6..fb487233d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (modellingThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modellingThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -124,31 +112,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (modellingThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modellingThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -165,44 +145,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(modellingThingReference.Actor.HasValue) - { - writer.WriteStringValue(modellingThingReference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (modellingThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (modellingThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(modellingThingReference.Iid); @@ -224,6 +185,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ModellingThingReference modellingThingReference) + { + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -236,32 +250,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -275,11 +283,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -297,11 +300,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -319,11 +317,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -337,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -355,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedrevisionnumber": - if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referencedRevisionNumber"u8); if(value != null) @@ -373,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedthing": - if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referencedThing"u8); if(value != null) @@ -391,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -409,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index d9095f126..3a8eb4d77 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (multiRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (multiRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (multiRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -132,18 +116,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(multiRelationshipRule.MinRelated); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - //if (multiRelationshipRule.RelatedCategory.Count > 0) - //{ - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -154,72 +134,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (multiRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (multiRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (multiRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -233,18 +193,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - //if (multiRelationshipRule.RelatedCategory.Count > 0) - //{ - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -255,72 +211,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (multiRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (multiRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (multiRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -334,18 +270,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - //if (multiRelationshipRule.RelatedCategory.Count > 0) - //{ - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -358,82 +290,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(multiRelationshipRule.Actor.HasValue) + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(multiRelationshipRule.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (multiRelationshipRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (multiRelationshipRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationshipRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationshipRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (multiRelationshipRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationshipRule.Iid); @@ -447,18 +349,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); - //if (multiRelationshipRule.RelatedCategory.Count > 0) - //{ - writer.WriteStartArray("relatedCategory"u8); - - foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedCategoryItem); - } + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("relationshipCategory"u8); writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); @@ -476,6 +374,106 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -488,32 +486,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -531,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -549,11 +536,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -571,11 +553,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -593,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -615,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -637,11 +604,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -655,11 +617,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -673,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "maxrelated": - if(!AllowedVersionsPerProperty["maxRelated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maxRelated"u8); if(value != null) @@ -691,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minrelated": - if(!AllowedVersionsPerProperty["minRelated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minRelated"u8); if(value != null) @@ -709,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -727,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -745,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedcategory": - if(!AllowedVersionsPerProperty["relatedCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -767,11 +699,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "relationshipcategory": - if(!AllowedVersionsPerProperty["relationshipCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("relationshipCategory"u8); if(value != null) @@ -785,11 +712,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -803,11 +725,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -821,11 +738,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 79380cf43..b34becb36 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,18 +77,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); - //if (multiRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); @@ -100,64 +92,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Iid); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("relatedThing"u8); - //if (multiRelationship.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (multiRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -165,77 +141,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (multiRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); - //if (multiRelationship.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (multiRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -245,31 +201,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (multiRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); - //if (multiRelationship.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -278,56 +226,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(multiRelationship.Actor.HasValue) + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(multiRelationship.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - //if (multiRelationship.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (multiRelationship.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (multiRelationship.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(multiRelationship.Iid); @@ -337,31 +263,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(multiRelationship.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (multiRelationship.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("relatedThing"u8); - //if (multiRelationship.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(multiRelationship.RevisionNumber); @@ -375,6 +293,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not MultiRelationship multiRelationship) + { + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -387,32 +387,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -430,11 +424,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -448,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -470,11 +454,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -492,11 +471,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -510,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -528,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -546,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -564,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -586,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -608,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -626,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index a2563af1d..da93a3762 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -98,31 +94,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (naturalLanguage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (naturalLanguage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -141,31 +129,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (naturalLanguage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (naturalLanguage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -184,44 +164,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(naturalLanguage.Actor.HasValue) - { - writer.WriteStringValue(naturalLanguage.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (naturalLanguage.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (naturalLanguage.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(naturalLanguage.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,32 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -296,11 +306,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -318,11 +323,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -340,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "nativename": - if(!AllowedVersionsPerProperty["nativeName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("nativeName"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index b95c667cb..29dc82cdb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,35 +79,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); - //if (nestedElement.ElementUsage.Count > 0) - //{ - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); writer.WritePropertyName("isVolatile"u8); writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WriteStartArray("nestedParameter"u8); - //if (nestedElement.NestedParameter.Count > 0) - //{ - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -122,44 +110,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); - //if (nestedElement.ElementUsage.Count > 0) - //{ - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedElement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedElement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -167,18 +143,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); - //if (nestedElement.NestedParameter.Count > 0) - //{ - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -189,44 +161,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); - //if (nestedElement.ElementUsage.Count > 0) - //{ - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedElement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedElement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -234,18 +194,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); - //if (nestedElement.NestedParameter.Count > 0) - //{ - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -256,57 +212,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(nestedElement.Actor.HasValue) - { - writer.WriteStringValue(nestedElement.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); - //if (nestedElement.ElementUsage.Count > 0) - //{ - writer.WriteStartArray("elementUsage"u8); - - foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(elementUsageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedElement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedElement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(nestedElement.Iid); @@ -314,18 +247,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(nestedElement.IsVolatile); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); - //if (nestedElement.NestedParameter.Count > 0) - //{ - writer.WriteStartArray("nestedParameter"u8); - - foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedParameterItem); - } + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(nestedElement.RevisionNumber); @@ -341,6 +270,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not NestedElement nestedElement) + { + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -353,32 +355,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -392,11 +388,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "elementusage": - if(!AllowedVersionsPerProperty["elementUsage"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -414,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -436,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -458,11 +439,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -476,11 +452,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isvolatile": - if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isVolatile"u8); if(value != null) @@ -494,11 +465,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -512,11 +478,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "nestedparameter": - if(!AllowedVersionsPerProperty["nestedParameter"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -534,11 +495,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -552,11 +508,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rootelement": - if(!AllowedVersionsPerProperty["rootElement"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("rootElement"u8); if(value != null) @@ -570,11 +521,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index 5feb723db..1f9956a58 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,7 +79,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.0.0"); writer.WritePropertyName("actualState"u8); - if(nestedParameter.ActualState.HasValue) + if (nestedParameter.ActualState.HasValue) { writer.WriteStringValue(nestedParameter.ActualState.Value); } @@ -113,7 +109,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.1.0"); writer.WritePropertyName("actualState"u8); - if(nestedParameter.ActualState.HasValue) + if (nestedParameter.ActualState.HasValue) { writer.WriteStringValue(nestedParameter.ActualState.Value); } @@ -128,31 +124,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedParameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedParameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -171,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.2.0"); writer.WritePropertyName("actualState"u8); - if(nestedParameter.ActualState.HasValue) + if (nestedParameter.ActualState.HasValue) { writer.WriteStringValue(nestedParameter.ActualState.Value); } @@ -186,31 +174,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedParameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedParameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -229,20 +209,9 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(nestedParameter.Actor.HasValue) - { - writer.WriteStringValue(nestedParameter.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("actualState"u8); - if(nestedParameter.ActualState.HasValue) + if (nestedParameter.ActualState.HasValue) { writer.WriteStringValue(nestedParameter.ActualState.Value); } @@ -257,31 +226,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(nestedParameter.AssociatedParameter); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (nestedParameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (nestedParameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("formula"u8); writer.WriteStringValue(nestedParameter.Formula); @@ -305,6 +266,76 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not NestedParameter nestedParameter) + { + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -317,32 +348,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "actualstate": - if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("actualState"u8); if(value != null) @@ -356,11 +381,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actualvalue": - if(!AllowedVersionsPerProperty["actualValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("actualValue"u8); if(value != null) @@ -374,11 +394,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "associatedparameter": - if(!AllowedVersionsPerProperty["associatedParameter"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("associatedParameter"u8); if(value != null) @@ -392,11 +407,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -410,11 +420,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -432,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -454,11 +454,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "formula": - if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("formula"u8); if(value != null) @@ -472,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -490,11 +480,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isvolatile": - if(!AllowedVersionsPerProperty["isVolatile"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isVolatile"u8); if(value != null) @@ -508,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -526,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -544,11 +519,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -562,11 +532,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 898aae7fc..0b69516b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -94,31 +90,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (notExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (notExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -133,31 +121,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (notExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (notExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -172,44 +152,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(notExpression.Actor.HasValue) - { - writer.WriteStringValue(notExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (notExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (notExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(notExpression.Iid); @@ -229,6 +190,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not NotExpression notExpression) + { + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -241,32 +253,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -280,11 +286,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -302,11 +303,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -324,11 +320,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -342,11 +333,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -360,11 +346,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -378,11 +359,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("term"u8); if(value != null) @@ -396,11 +372,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index b2967d253..d677a8aed 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,76 +77,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (option.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (option.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (option.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (option.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - //if (option.NestedElement.Count > 0) - //{ - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedElementItem); - } + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -159,85 +135,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (option.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (option.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (option.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (option.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (option.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (option.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -245,18 +197,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - //if (option.NestedElement.Count > 0) - //{ - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedElementItem); - } + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -265,85 +213,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (option.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (option.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (option.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (option.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (option.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (option.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -351,18 +275,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - //if (option.NestedElement.Count > 0) - //{ - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedElementItem); - } + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -373,95 +293,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(option.Actor.HasValue) + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(option.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (option.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (option.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (option.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (option.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (option.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (option.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(option.Iid); @@ -469,18 +355,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); - //if (option.NestedElement.Count > 0) - //{ - writer.WriteStartArray("nestedElement"u8); - - foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(nestedElementItem); - } + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(option.RevisionNumber); @@ -496,6 +378,108 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -508,32 +492,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +529,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -573,11 +546,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -591,11 +559,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +576,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -635,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -657,11 +610,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "nestedelement": - if(!AllowedVersionsPerProperty["nestedElement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -755,11 +683,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -773,11 +696,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -791,11 +709,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index 69d0c0183..fd8f5752c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -87,49 +83,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (orExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (orExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (orExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -137,49 +121,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (orExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (orExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (orExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -187,62 +159,39 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (orExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(orExpression.Actor.HasValue) - { - writer.WriteStringValue(orExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (orExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (orExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(orExpression.Iid); @@ -250,18 +199,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); - //if (orExpression.Term.Count > 0) - //{ - writer.WriteStartArray("term"u8); - - foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(termItem); - } + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(orExpression.ThingPreference); @@ -273,6 +218,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -285,32 +289,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -324,11 +322,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -346,11 +339,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "term": - if(!AllowedVersionsPerProperty["term"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -444,11 +412,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 0fa8b6e72..2bdd2063c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (ordinalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ordinalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ordinalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ordinalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -163,88 +143,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - //if (ordinalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (ordinalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ordinalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ordinalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ordinalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ordinalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -254,18 +210,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ordinalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -289,88 +241,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - //if (ordinalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (ordinalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ordinalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ordinalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ordinalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ordinalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -380,18 +308,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ordinalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -417,98 +341,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - //if (ordinalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(ordinalScale.Actor.HasValue) + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(ordinalScale.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (ordinalScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ordinalScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ordinalScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ordinalScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ordinalScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ordinalScale.Iid); @@ -518,18 +408,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ordinalScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); @@ -555,18 +441,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ordinalScale.Unit); writer.WritePropertyName("useShortNameValues"u8); writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); - //if (ordinalScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -576,6 +458,128 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not OrdinalScale ordinalScale) + { + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -588,32 +592,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -631,11 +629,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -649,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -671,11 +659,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -693,11 +676,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -715,11 +693,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -737,11 +710,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -755,11 +723,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -773,11 +736,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ismaximuminclusive": - if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) @@ -791,11 +749,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isminimuminclusive": - if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) @@ -809,11 +762,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mappingtoreferencescale": - if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -831,11 +779,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "maximumpermissiblevalue": - if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) @@ -849,11 +792,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minimumpermissiblevalue": - if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minimumPermissibleValue"u8); if(value != null) @@ -867,11 +805,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -885,11 +818,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -903,11 +831,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("negativeValueConnotation"u8); if(value != null) @@ -921,11 +844,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("numberSet"u8); if(value != null) @@ -939,11 +857,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("positiveValueConnotation"u8); if(value != null) @@ -957,11 +870,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -975,11 +883,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -993,11 +896,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1011,11 +909,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) @@ -1029,11 +922,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "useshortnamevalues": - if(!AllowedVersionsPerProperty["useShortNameValues"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("useShortNameValues"u8); if(value != null) @@ -1047,11 +935,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 177b9768e..b39dc7d71 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -98,31 +94,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (organization.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (organization.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -141,31 +129,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (organization.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (organization.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -184,44 +164,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(organization.Actor.HasValue) - { - writer.WriteStringValue(organization.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (organization.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (organization.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(organization.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,32 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -296,11 +306,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -318,11 +323,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -340,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 697f0bd5f..957be2f25 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (organizationalParticipant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (organizationalParticipant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -122,44 +110,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(organizationalParticipant.Actor.HasValue) - { - writer.WriteStringValue(organizationalParticipant.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (organizationalParticipant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (organizationalParticipant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(organizationalParticipant.Iid); @@ -179,6 +148,57 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not OrganizationalParticipant organizationalParticipant) + { + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -191,32 +211,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -230,11 +244,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -252,11 +261,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -274,11 +278,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -292,11 +291,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -310,11 +304,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organization": - if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("organization"u8); if(value != null) @@ -328,11 +317,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -346,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 070d8d83b..2a66a98f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,35 +79,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (ownedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ownedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(ownedStyle.FillColor.HasValue) + if (ownedStyle.FillColor.HasValue) { writer.WriteStringValue(ownedStyle.FillColor.Value); } @@ -122,7 +110,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(ownedStyle.FillOpacity.HasValue) + if (ownedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.FillOpacity.Value); } @@ -133,7 +121,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(ownedStyle.FontBold.HasValue) + if (ownedStyle.FontBold.HasValue) { writer.WriteBooleanValue(ownedStyle.FontBold.Value); } @@ -144,7 +132,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(ownedStyle.FontColor.HasValue) + if (ownedStyle.FontColor.HasValue) { writer.WriteStringValue(ownedStyle.FontColor.Value); } @@ -155,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(ownedStyle.FontItalic.HasValue) + if (ownedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(ownedStyle.FontItalic.Value); } @@ -168,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ownedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(ownedStyle.FontSize.HasValue) + if (ownedStyle.FontSize.HasValue) { writer.WriteNumberValue(ownedStyle.FontSize.Value); } @@ -179,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(ownedStyle.FontStrokeThrough.HasValue) + if (ownedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); } @@ -190,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(ownedStyle.FontUnderline.HasValue) + if (ownedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); } @@ -209,7 +197,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ownedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(ownedStyle.StrokeColor.HasValue) + if (ownedStyle.StrokeColor.HasValue) { writer.WriteStringValue(ownedStyle.StrokeColor.Value); } @@ -220,7 +208,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(ownedStyle.StrokeOpacity.HasValue) + if (ownedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); } @@ -231,7 +219,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(ownedStyle.StrokeWidth.HasValue) + if (ownedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); } @@ -240,52 +228,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (ownedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); + writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (ownedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ownedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(ownedStyle.FillColor.HasValue) + if (ownedStyle.FillColor.HasValue) { writer.WriteStringValue(ownedStyle.FillColor.Value); } @@ -296,7 +273,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(ownedStyle.FillOpacity.HasValue) + if (ownedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.FillOpacity.Value); } @@ -307,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(ownedStyle.FontBold.HasValue) + if (ownedStyle.FontBold.HasValue) { writer.WriteBooleanValue(ownedStyle.FontBold.Value); } @@ -318,7 +295,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(ownedStyle.FontColor.HasValue) + if (ownedStyle.FontColor.HasValue) { writer.WriteStringValue(ownedStyle.FontColor.Value); } @@ -329,7 +306,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(ownedStyle.FontItalic.HasValue) + if (ownedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(ownedStyle.FontItalic.Value); } @@ -342,7 +319,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ownedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(ownedStyle.FontSize.HasValue) + if (ownedStyle.FontSize.HasValue) { writer.WriteNumberValue(ownedStyle.FontSize.Value); } @@ -353,7 +330,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(ownedStyle.FontStrokeThrough.HasValue) + if (ownedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); } @@ -364,7 +341,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(ownedStyle.FontUnderline.HasValue) + if (ownedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); } @@ -383,7 +360,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ownedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(ownedStyle.StrokeColor.HasValue) + if (ownedStyle.StrokeColor.HasValue) { writer.WriteStringValue(ownedStyle.StrokeColor.Value); } @@ -394,7 +371,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(ownedStyle.StrokeOpacity.HasValue) + if (ownedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); } @@ -405,7 +382,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(ownedStyle.StrokeWidth.HasValue) + if (ownedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); } @@ -416,64 +393,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); - //if (ownedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(ownedStyle.Actor.HasValue) - { - writer.WriteStringValue(ownedStyle.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (ownedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ownedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(ownedStyle.FillColor.HasValue) + if (ownedStyle.FillColor.HasValue) { writer.WriteStringValue(ownedStyle.FillColor.Value); } @@ -484,7 +438,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(ownedStyle.FillOpacity.HasValue) + if (ownedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.FillOpacity.Value); } @@ -495,7 +449,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(ownedStyle.FontBold.HasValue) + if (ownedStyle.FontBold.HasValue) { writer.WriteBooleanValue(ownedStyle.FontBold.Value); } @@ -506,7 +460,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(ownedStyle.FontColor.HasValue) + if (ownedStyle.FontColor.HasValue) { writer.WriteStringValue(ownedStyle.FontColor.Value); } @@ -517,7 +471,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(ownedStyle.FontItalic.HasValue) + if (ownedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(ownedStyle.FontItalic.Value); } @@ -530,7 +484,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ownedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(ownedStyle.FontSize.HasValue) + if (ownedStyle.FontSize.HasValue) { writer.WriteNumberValue(ownedStyle.FontSize.Value); } @@ -541,7 +495,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(ownedStyle.FontStrokeThrough.HasValue) + if (ownedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); } @@ -552,7 +506,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(ownedStyle.FontUnderline.HasValue) + if (ownedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); } @@ -571,7 +525,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ownedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(ownedStyle.StrokeColor.HasValue) + if (ownedStyle.StrokeColor.HasValue) { writer.WriteStringValue(ownedStyle.StrokeColor.Value); } @@ -582,7 +536,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(ownedStyle.StrokeOpacity.HasValue) + if (ownedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); } @@ -593,7 +547,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(ownedStyle.StrokeWidth.HasValue) + if (ownedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); } @@ -604,18 +558,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); - //if (ownedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -625,6 +575,190 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not OwnedStyle ownedStyle) + { + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -637,32 +771,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -676,11 +804,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -698,11 +821,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -720,11 +838,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "fillcolor": - if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fillColor"u8); if(value != null) @@ -738,11 +851,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fillopacity": - if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fillOpacity"u8); if(value != null) @@ -756,11 +864,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontbold": - if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontBold"u8); if(value != null) @@ -774,11 +877,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontcolor": - if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontColor"u8); if(value != null) @@ -792,11 +890,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontitalic": - if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontItalic"u8); if(value != null) @@ -810,11 +903,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontname": - if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontName"u8); if(value != null) @@ -828,11 +916,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontsize": - if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontSize"u8); if(value != null) @@ -846,11 +929,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontstrokethrough": - if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontStrokeThrough"u8); if(value != null) @@ -864,11 +942,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontunderline": - if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontUnderline"u8); if(value != null) @@ -882,11 +955,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -900,11 +968,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -918,11 +981,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -936,11 +994,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -954,11 +1007,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokecolor": - if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeColor"u8); if(value != null) @@ -972,11 +1020,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokeopacity": - if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeOpacity"u8); if(value != null) @@ -990,11 +1033,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokewidth": - if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeWidth"u8); if(value != null) @@ -1008,11 +1046,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1026,11 +1059,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "usedcolor": - if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index 71c3cb0f6..c4701de65 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (page.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (page.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (page.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); - //if (page.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -152,48 +132,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (page.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (page.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (page.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -201,18 +169,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); - //if (page.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -225,58 +189,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(page.Actor.HasValue) - { - writer.WriteStringValue(page.Actor.Value); - } - else + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - //if (page.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(page.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (page.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (page.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(page.Iid); @@ -284,18 +226,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); - //if (page.Note.Count > 0) - //{ - writer.WriteStartArray("note"u8); - - foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(noteItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("owner"u8); writer.WriteStringValue(page.Owner); @@ -313,6 +251,82 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Page page) + { + throw new ArgumentException("The thing shall be a Page", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -325,32 +339,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -386,11 +389,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -404,11 +402,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -426,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -448,11 +436,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -466,11 +449,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -484,11 +462,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -502,11 +475,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "note": - if(!AllowedVersionsPerProperty["note"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -524,11 +492,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -542,11 +505,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -560,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -578,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index dcc2931db..1c85ae8d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterGroup.ClassKind.ToString()); writer.WritePropertyName("containingGroup"u8); - if(parameterGroup.ContainingGroup.HasValue) + if (parameterGroup.ContainingGroup.HasValue) { writer.WriteStringValue(parameterGroup.ContainingGroup.Value); } @@ -107,7 +103,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterGroup.ClassKind.ToString()); writer.WritePropertyName("containingGroup"u8); - if(parameterGroup.ContainingGroup.HasValue) + if (parameterGroup.ContainingGroup.HasValue) { writer.WriteStringValue(parameterGroup.ContainingGroup.Value); } @@ -116,30 +112,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (parameterGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -156,7 +145,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterGroup.ClassKind.ToString()); writer.WritePropertyName("containingGroup"u8); - if(parameterGroup.ContainingGroup.HasValue) + if (parameterGroup.ContainingGroup.HasValue) { writer.WriteStringValue(parameterGroup.ContainingGroup.Value); } @@ -165,30 +154,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (parameterGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -203,22 +185,11 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterGroup.Actor.HasValue) - { - writer.WriteStringValue(parameterGroup.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterGroup.ClassKind.ToString()); writer.WritePropertyName("containingGroup"u8); - if(parameterGroup.ContainingGroup.HasValue) + if (parameterGroup.ContainingGroup.HasValue) { writer.WriteStringValue(parameterGroup.ContainingGroup.Value); } @@ -227,30 +198,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (parameterGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); + writer.WriteStartArray("excludedDomain"u8); - foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterGroup.Iid); @@ -270,6 +234,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -282,32 +307,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -321,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "containinggroup": - if(!AllowedVersionsPerProperty["containingGroup"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("containingGroup"u8); if(value != null) @@ -339,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -361,11 +370,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -383,11 +387,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -401,11 +400,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -419,11 +413,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -437,11 +426,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -455,11 +439,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 68aaad386..7651356d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,64 +85,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameterOverride.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); - //if (parameterOverride.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverride.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverride.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -156,64 +136,48 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameterOverride.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); - //if (parameterOverride.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverride.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverride.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -223,77 +187,50 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameterOverride.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameterOverride.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterOverride.Actor.HasValue) - { - writer.WriteStringValue(parameterOverride.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverride.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverride.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterOverride.Iid); @@ -303,35 +240,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterOverride.Owner); writer.WritePropertyName("parameter"u8); writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameterOverride.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterOverride.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameterOverride.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -341,6 +270,79 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterOverride parameterOverride) + { + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -353,32 +355,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -392,11 +388,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -414,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -436,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -454,11 +435,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -472,11 +448,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -490,11 +461,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parameter": - if(!AllowedVersionsPerProperty["parameter"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameter"u8); if(value != null) @@ -508,11 +474,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametersubscription": - if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -530,11 +491,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -548,11 +504,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -566,11 +517,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueset": - if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 425d31e71..7c73970d0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -102,31 +98,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -148,31 +136,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -193,45 +173,26 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterOverrideValueSet.Actor.HasValue) - { - writer.WriteStringValue(parameterOverrideValueSet.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterOverrideValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterOverrideValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -257,6 +218,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) + { + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -269,32 +288,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -308,19 +321,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "computed": - if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -338,11 +341,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -360,19 +358,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "formula": - if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -386,19 +374,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "manual": - if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +390,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalueset": - if(!AllowedVersionsPerProperty["parameterValueSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterValueSet"u8); if(value != null) @@ -430,27 +403,12 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "published": - if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); break; case "reference": - if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -464,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -482,11 +435,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueswitch": - if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("valueSwitch"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index 212b3b2a5..f25295cb7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,7 +85,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); - if(parameter.Group.HasValue) + if (parameter.Group.HasValue) { writer.WriteStringValue(parameter.Group.Value); } @@ -104,24 +100,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.IsOptionDependent); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameter.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); - if(parameter.RequestedBy.HasValue) + if (parameter.RequestedBy.HasValue) { writer.WriteStringValue(parameter.RequestedBy.Value); } @@ -134,7 +126,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameter.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameter.Scale.HasValue) + if (parameter.Scale.HasValue) { writer.WriteStringValue(parameter.Scale.Value); } @@ -145,7 +137,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("stateDependence"u8); - if(parameter.StateDependence.HasValue) + if (parameter.StateDependence.HasValue) { writer.WriteStringValue(parameter.StateDependence.Value); } @@ -154,17 +146,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (parameter.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); + writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": @@ -173,37 +162,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); - if(parameter.Group.HasValue) + if (parameter.Group.HasValue) { writer.WriteStringValue(parameter.Group.Value); } @@ -220,24 +201,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameter.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); - if(parameter.RequestedBy.HasValue) + if (parameter.RequestedBy.HasValue) { writer.WriteStringValue(parameter.RequestedBy.Value); } @@ -250,7 +227,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameter.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameter.Scale.HasValue) + if (parameter.Scale.HasValue) { writer.WriteStringValue(parameter.Scale.Value); } @@ -261,7 +238,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("stateDependence"u8); - if(parameter.StateDependence.HasValue) + if (parameter.StateDependence.HasValue) { writer.WriteStringValue(parameter.StateDependence.Value); } @@ -270,17 +247,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (parameter.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); + writer.WriteStartArray("valueSet"u8); - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": @@ -289,37 +263,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); - if(parameter.Group.HasValue) + if (parameter.Group.HasValue) { writer.WriteStringValue(parameter.Group.Value); } @@ -336,24 +302,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameter.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); - if(parameter.RequestedBy.HasValue) + if (parameter.RequestedBy.HasValue) { writer.WriteStringValue(parameter.RequestedBy.Value); } @@ -366,7 +328,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameter.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameter.Scale.HasValue) + if (parameter.Scale.HasValue) { writer.WriteStringValue(parameter.Scale.Value); } @@ -377,7 +339,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("stateDependence"u8); - if(parameter.StateDependence.HasValue) + if (parameter.StateDependence.HasValue) { writer.WriteStringValue(parameter.StateDependence.Value); } @@ -388,68 +350,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameter.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameter.Actor.HasValue) - { - writer.WriteStringValue(parameter.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameter.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameter.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("expectsOverride"u8); writer.WriteBooleanValue(parameter.ExpectsOverride); writer.WritePropertyName("group"u8); - if(parameter.Group.HasValue) + if (parameter.Group.HasValue) { writer.WriteStringValue(parameter.Group.Value); } @@ -466,24 +405,20 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("owner"u8); writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); - //if (parameter.ParameterSubscription.Count > 0) - //{ - writer.WriteStartArray("parameterSubscription"u8); - - foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterSubscriptionItem); - } + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("parameterType"u8); writer.WriteStringValue(parameter.ParameterType); writer.WritePropertyName("requestedBy"u8); - if(parameter.RequestedBy.HasValue) + if (parameter.RequestedBy.HasValue) { writer.WriteStringValue(parameter.RequestedBy.Value); } @@ -496,7 +431,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameter.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameter.Scale.HasValue) + if (parameter.Scale.HasValue) { writer.WriteStringValue(parameter.Scale.Value); } @@ -507,7 +442,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("stateDependence"u8); - if(parameter.StateDependence.HasValue) + if (parameter.StateDependence.HasValue) { writer.WriteStringValue(parameter.StateDependence.Value); } @@ -518,18 +453,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameter.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -539,6 +470,129 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Parameter parameter) + { + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -551,32 +605,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "allowdifferentownerofoverride": - if(!AllowedVersionsPerProperty["allowDifferentOwnerOfOverride"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); if(value != null) @@ -590,11 +638,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -608,11 +651,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -630,11 +668,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -652,11 +685,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "expectsoverride": - if(!AllowedVersionsPerProperty["expectsOverride"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("expectsOverride"u8); if(value != null) @@ -670,11 +698,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "group": - if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("group"u8); if(value != null) @@ -688,11 +711,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -706,11 +724,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isoptiondependent": - if(!AllowedVersionsPerProperty["isOptionDependent"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isOptionDependent"u8); if(value != null) @@ -724,11 +737,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -742,11 +750,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -760,11 +763,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametersubscription": - if(!AllowedVersionsPerProperty["parameterSubscription"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -782,11 +780,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -800,11 +793,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "requestedby": - if(!AllowedVersionsPerProperty["requestedBy"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("requestedBy"u8); if(value != null) @@ -818,11 +806,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -836,11 +819,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -854,11 +832,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "statedependence": - if(!AllowedVersionsPerProperty["stateDependence"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("stateDependence"u8); if(value != null) @@ -872,11 +845,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -890,11 +858,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueset": - if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 440b30b32..e0a587cd5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,49 +85,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterSubscription.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); - //if (parameterSubscription.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscription.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscription.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -141,49 +125,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterSubscription.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); - //if (parameterSubscription.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscription.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscription.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -195,60 +167,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterSubscription.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameterSubscription.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterSubscription.Actor.HasValue) - { - writer.WriteStringValue(parameterSubscription.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscription.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscription.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscription.Iid); @@ -260,18 +209,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterSubscription.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); - //if (parameterSubscription.ValueSet.Count > 0) - //{ - writer.WriteStartArray("valueSet"u8); - - foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueSetItem); - } + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -281,6 +226,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -293,32 +299,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -332,11 +332,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -354,11 +349,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -466,11 +431,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueset": - if(!AllowedVersionsPerProperty["valueSet"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 0d52bc2f0..5aaa4c465 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -97,31 +93,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -139,31 +127,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -181,44 +161,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterSubscriptionValueSet.Actor.HasValue) - { - writer.WriteStringValue(parameterSubscriptionValueSet.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterSubscriptionValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterSubscriptionValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterSubscriptionValueSet.Iid); @@ -241,6 +202,60 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) + { + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -253,32 +268,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -292,11 +301,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -314,11 +318,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -336,11 +335,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -354,19 +348,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "manual": - if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -380,11 +364,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -398,11 +377,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "subscribedvalueset": - if(!AllowedVersionsPerProperty["subscribedValueSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("subscribedValueSet"u8); if(value != null) @@ -416,11 +390,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -434,11 +403,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueswitch": - if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("valueSwitch"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 0d2bc1743..049c4286a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -91,7 +87,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameterTypeComponent.Scale.HasValue) + if (parameterTypeComponent.Scale.HasValue) { writer.WriteStringValue(parameterTypeComponent.Scale.Value); } @@ -107,31 +103,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterTypeComponent.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterTypeComponent.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -143,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameterTypeComponent.Scale.HasValue) + if (parameterTypeComponent.Scale.HasValue) { writer.WriteStringValue(parameterTypeComponent.Scale.Value); } @@ -159,31 +147,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterTypeComponent.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterTypeComponent.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -195,7 +175,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameterTypeComponent.Scale.HasValue) + if (parameterTypeComponent.Scale.HasValue) { writer.WriteStringValue(parameterTypeComponent.Scale.Value); } @@ -211,44 +191,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterTypeComponent.Actor.HasValue) - { - writer.WriteStringValue(parameterTypeComponent.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterTypeComponent.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterTypeComponent.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterTypeComponent.Iid); @@ -260,7 +221,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); writer.WritePropertyName("scale"u8); - if(parameterTypeComponent.Scale.HasValue) + if (parameterTypeComponent.Scale.HasValue) { writer.WriteStringValue(parameterTypeComponent.Scale.Value); } @@ -281,6 +242,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterTypeComponent parameterTypeComponent) + { + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -293,32 +318,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -332,11 +351,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -354,11 +368,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -376,11 +385,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -394,11 +398,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +411,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -430,11 +424,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -466,11 +450,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -484,11 +463,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 1a48750f0..5de2a34d9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,7 +79,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.0.0"); writer.WritePropertyName("actualOption"u8); - if(parameterValueSet.ActualOption.HasValue) + if (parameterValueSet.ActualOption.HasValue) { writer.WriteStringValue(parameterValueSet.ActualOption.Value); } @@ -94,7 +90,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actualState"u8); - if(parameterValueSet.ActualState.HasValue) + if (parameterValueSet.ActualState.HasValue) { writer.WriteStringValue(parameterValueSet.ActualState.Value); } @@ -121,7 +117,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.1.0"); writer.WritePropertyName("actualOption"u8); - if(parameterValueSet.ActualOption.HasValue) + if (parameterValueSet.ActualOption.HasValue) { writer.WriteStringValue(parameterValueSet.ActualOption.Value); } @@ -132,7 +128,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actualState"u8); - if(parameterValueSet.ActualState.HasValue) + if (parameterValueSet.ActualState.HasValue) { writer.WriteStringValue(parameterValueSet.ActualState.Value); } @@ -144,31 +140,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -187,7 +175,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.2.0"); writer.WritePropertyName("actualOption"u8); - if(parameterValueSet.ActualOption.HasValue) + if (parameterValueSet.ActualOption.HasValue) { writer.WriteStringValue(parameterValueSet.ActualOption.Value); } @@ -198,7 +186,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actualState"u8); - if(parameterValueSet.ActualState.HasValue) + if (parameterValueSet.ActualState.HasValue) { writer.WriteStringValue(parameterValueSet.ActualState.Value); } @@ -210,31 +198,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -253,20 +233,9 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parameterValueSet.Actor.HasValue) - { - writer.WriteStringValue(parameterValueSet.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("actualOption"u8); - if(parameterValueSet.ActualOption.HasValue) + if (parameterValueSet.ActualOption.HasValue) { writer.WriteStringValue(parameterValueSet.ActualOption.Value); } @@ -277,7 +246,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("actualState"u8); - if(parameterValueSet.ActualState.HasValue) + if (parameterValueSet.ActualState.HasValue) { writer.WriteStringValue(parameterValueSet.ActualState.Value); } @@ -289,31 +258,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterValueSet.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterValueSet.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); writer.WritePropertyName("iid"u8); @@ -337,6 +298,84 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterValueSet parameterValueSet) + { + throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -349,32 +388,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "actualoption": - if(!AllowedVersionsPerProperty["actualOption"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("actualOption"u8); if(value != null) @@ -388,11 +421,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "actualstate": - if(!AllowedVersionsPerProperty["actualState"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("actualState"u8); if(value != null) @@ -406,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -424,19 +447,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "computed": - if(!AllowedVersionsPerProperty["computed"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -454,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -476,19 +484,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "formula": - if(!AllowedVersionsPerProperty["formula"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -502,19 +500,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "manual": - if(!AllowedVersionsPerProperty["manual"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -528,27 +516,12 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "published": - if(!AllowedVersionsPerProperty["published"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); break; case "reference": - if(!AllowedVersionsPerProperty["reference"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -562,11 +535,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -580,11 +548,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valueswitch": - if(!AllowedVersionsPerProperty["valueSwitch"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("valueSwitch"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index c46de9c74..e795bb993 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (parameterizedCategoryRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (parameterizedCategoryRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (parameterizedCategoryRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - //if (parameterizedCategoryRule.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -150,74 +130,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (parameterizedCategoryRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (parameterizedCategoryRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (parameterizedCategoryRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -227,18 +187,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - //if (parameterizedCategoryRule.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -247,74 +203,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (parameterizedCategoryRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (parameterizedCategoryRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (parameterizedCategoryRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -324,18 +260,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - //if (parameterizedCategoryRule.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -346,84 +278,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(parameterizedCategoryRule.Actor.HasValue) + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(parameterizedCategoryRule.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (parameterizedCategoryRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("category"u8); writer.WriteStringValue(parameterizedCategoryRule.Category); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (parameterizedCategoryRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (parameterizedCategoryRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parameterizedCategoryRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (parameterizedCategoryRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parameterizedCategoryRule.Iid); @@ -433,18 +335,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); - //if (parameterizedCategoryRule.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) + { + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("category"u8); if(value != null) @@ -533,11 +516,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -551,11 +529,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -573,11 +546,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -595,11 +563,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -617,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -639,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -657,11 +610,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -675,11 +623,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -693,11 +636,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -711,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 04d2ce36a..bc0244fb8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,18 +79,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("expression"u8); - //if (parametricConstraint.Expression.Count > 0) - //{ - writer.WriteStartArray("expression"u8); - - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(expressionItem); - } + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -102,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parametricConstraint.RevisionNumber); writer.WritePropertyName("topExpression"u8); - if(parametricConstraint.TopExpression.HasValue) + if (parametricConstraint.TopExpression.HasValue) { writer.WriteStringValue(parametricConstraint.TopExpression.Value); } @@ -116,44 +108,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parametricConstraint.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parametricConstraint.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); - //if (parametricConstraint.Expression.Count > 0) - //{ - writer.WriteStartArray("expression"u8); - - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(expressionItem); - } + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -163,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(parametricConstraint.RevisionNumber); writer.WritePropertyName("topExpression"u8); - if(parametricConstraint.TopExpression.HasValue) + if (parametricConstraint.TopExpression.HasValue) { writer.WriteStringValue(parametricConstraint.TopExpression.Value); } @@ -177,44 +157,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parametricConstraint.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parametricConstraint.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); - //if (parametricConstraint.Expression.Count > 0) - //{ - writer.WriteStartArray("expression"u8); - - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(expressionItem); - } + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -226,7 +194,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parametricConstraint.ThingPreference); writer.WritePropertyName("topExpression"u8); - if(parametricConstraint.TopExpression.HasValue) + if (parametricConstraint.TopExpression.HasValue) { writer.WriteStringValue(parametricConstraint.TopExpression.Value); } @@ -238,57 +206,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(parametricConstraint.Actor.HasValue) - { - writer.WriteStringValue(parametricConstraint.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (parametricConstraint.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (parametricConstraint.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("expression"u8); - //if (parametricConstraint.Expression.Count > 0) - //{ - writer.WriteStartArray("expression"u8); - - foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(expressionItem); - } + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(parametricConstraint.Iid); @@ -300,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(parametricConstraint.ThingPreference); writer.WritePropertyName("topExpression"u8); - if(parametricConstraint.TopExpression.HasValue) + if (parametricConstraint.TopExpression.HasValue) { writer.WriteStringValue(parametricConstraint.TopExpression.Value); } @@ -317,6 +262,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParametricConstraint parametricConstraint) + { + throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -329,32 +343,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -368,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -390,11 +393,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -412,11 +410,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "expression": - if(!AllowedVersionsPerProperty["expression"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -434,11 +427,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -452,11 +440,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -470,11 +453,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -488,11 +466,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -506,11 +479,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "topexpression": - if(!AllowedVersionsPerProperty["topExpression"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("topExpression"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index c9e11a2a7..a2958cfe2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -100,31 +96,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (participantPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -143,31 +131,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (participantPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -186,44 +166,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.3.0"); writer.WritePropertyName("accessRight"u8); writer.WriteStringValue(participantPermission.AccessRight.ToString()); - writer.WritePropertyName("actor"u8); - - if(participantPermission.Actor.HasValue) - { - writer.WriteStringValue(participantPermission.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (participantPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantPermission.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,14 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + { + return; + } + + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { switch(propertyName.ToLower()) { case "accessright": - if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("accessRight"u8); if(value != null) @@ -276,31 +304,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteNullValue(); } - break; - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -314,11 +319,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -336,11 +336,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "objectclass": - if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("objectClass"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 2d546615d..d7e4c06a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (participantRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (participantRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (participantRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -128,18 +112,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(participantRole.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - //if (participantRole.ParticipantPermission.Count > 0) - //{ - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantPermissionItem); - } + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -148,72 +128,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (participantRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (participantRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participantRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (participantRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -223,18 +183,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - //if (participantRole.ParticipantPermission.Count > 0) - //{ - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantPermissionItem); - } + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -243,72 +199,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (participantRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (participantRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participantRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (participantRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -318,18 +254,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - //if (participantRole.ParticipantPermission.Count > 0) - //{ - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantPermissionItem); - } + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -340,82 +272,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(participantRole.Actor.HasValue) + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(participantRole.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (participantRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (participantRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participantRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participantRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (participantRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participantRole.Iid); @@ -425,18 +327,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); - //if (participantRole.ParticipantPermission.Count > 0) - //{ - writer.WriteStartArray("participantPermission"u8); - - foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantPermissionItem); - } + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(participantRole.RevisionNumber); @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ParticipantRole participantRole) + { + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -525,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -631,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -649,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -667,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -685,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "participantpermission": - if(!AllowedVersionsPerProperty["participantPermission"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -725,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -743,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index 79cb9b9ed..e9b2d11ea 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,18 +79,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.0.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); - //if (participant.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -113,44 +105,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); - //if (participant.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -171,44 +151,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); - //if (participant.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -229,57 +197,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(participant.Actor.HasValue) - { - writer.WriteStringValue(participant.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); - //if (participant.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (participant.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (participant.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(participant.Iid); @@ -305,6 +250,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Participant participant) + { + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -317,32 +329,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -356,11 +362,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "domain": - if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -378,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -400,11 +396,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -422,11 +413,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -440,11 +426,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isActive"u8); if(value != null) @@ -458,11 +439,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -476,11 +452,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "person": - if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("person"u8); if(value != null) @@ -494,11 +465,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -512,11 +478,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "role": - if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("role"u8); if(value != null) @@ -530,11 +491,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "selecteddomain": - if(!AllowedVersionsPerProperty["selectedDomain"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("selectedDomain"u8); if(value != null) @@ -548,11 +504,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index 1fbca5451..4a50aed63 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -100,31 +96,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (personPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -143,31 +131,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personPermission.AccessRight.ToString()); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (personPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -186,44 +166,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.3.0"); writer.WritePropertyName("accessRight"u8); writer.WriteStringValue(personPermission.AccessRight.ToString()); - writer.WritePropertyName("actor"u8); - - if(personPermission.Actor.HasValue) - { - writer.WriteStringValue(personPermission.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (personPermission.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personPermission.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personPermission.Iid); @@ -245,6 +206,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -257,14 +273,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + { + return; + } + + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { switch(propertyName.ToLower()) { case "accessright": - if(!AllowedVersionsPerProperty["accessRight"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("accessRight"u8); if(value != null) @@ -276,31 +304,8 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteNullValue(); } - break; - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } - - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } - break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -314,11 +319,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -336,11 +336,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -358,11 +353,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "objectclass": - if(!AllowedVersionsPerProperty["objectClass"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("objectClass"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 58c75b5e2..1f9f019e1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (personRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (personRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (personRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -128,18 +112,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(personRole.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - //if (personRole.PersonPermission.Count > 0) - //{ - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personPermissionItem); - } + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -148,72 +128,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (personRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (personRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (personRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (personRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -223,18 +183,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - //if (personRole.PersonPermission.Count > 0) - //{ - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personPermissionItem); - } + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -243,72 +199,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (personRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (personRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (personRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (personRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -318,18 +254,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - //if (personRole.PersonPermission.Count > 0) - //{ - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personPermissionItem); - } + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -340,82 +272,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(personRole.Actor.HasValue) + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(personRole.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (personRole.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (personRole.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (personRole.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (personRole.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (personRole.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(personRole.Iid); @@ -425,18 +327,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); - //if (personRole.PersonPermission.Count > 0) - //{ - writer.WriteStartArray("personPermission"u8); - - foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personPermissionItem); - } + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(personRole.RevisionNumber); @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not PersonRole personRole) + { + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -525,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -631,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -649,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -667,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -685,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "personpermission": - if(!AllowedVersionsPerProperty["personPermission"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -725,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -743,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index 1f080af4b..d3637c846 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); - if(person.DefaultDomain.HasValue) + if (person.DefaultDomain.HasValue) { writer.WriteStringValue(person.DefaultDomain.Value); } @@ -96,7 +92,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultEmailAddress"u8); - if(person.DefaultEmailAddress.HasValue) + if (person.DefaultEmailAddress.HasValue) { writer.WriteStringValue(person.DefaultEmailAddress.Value); } @@ -107,7 +103,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultTelephoneNumber"u8); - if(person.DefaultTelephoneNumber.HasValue) + if (person.DefaultTelephoneNumber.HasValue) { writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } @@ -116,17 +112,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (person.EmailAddress.Count > 0) - //{ - writer.WriteStartArray("emailAddress"u8); + writer.WriteStartArray("emailAddress"u8); - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(emailAddressItem); - } + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -138,7 +131,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(person.IsDeprecated); writer.WritePropertyName("organization"u8); - if(person.Organization.HasValue) + if (person.Organization.HasValue) { writer.WriteStringValue(person.Organization.Value); } @@ -155,7 +148,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(person.RevisionNumber); writer.WritePropertyName("role"u8); - if(person.Role.HasValue) + if (person.Role.HasValue) { writer.WriteStringValue(person.Role.Value); } @@ -168,31 +161,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - //if (person.TelephoneNumber.Count > 0) - //{ - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(telephoneNumberItem); - } + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("userPreference"u8); - //if (person.UserPreference.Count > 0) - //{ - writer.WriteStartArray("userPreference"u8); - - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(userPreferenceItem); - } + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": @@ -201,7 +186,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); - if(person.DefaultDomain.HasValue) + if (person.DefaultDomain.HasValue) { writer.WriteStringValue(person.DefaultDomain.Value); } @@ -212,7 +197,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultEmailAddress"u8); - if(person.DefaultEmailAddress.HasValue) + if (person.DefaultEmailAddress.HasValue) { writer.WriteStringValue(person.DefaultEmailAddress.Value); } @@ -223,7 +208,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultTelephoneNumber"u8); - if(person.DefaultTelephoneNumber.HasValue) + if (person.DefaultTelephoneNumber.HasValue) { writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } @@ -232,43 +217,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (person.EmailAddress.Count > 0) - //{ - writer.WriteStartArray("emailAddress"u8); + writer.WriteStartArray("emailAddress"u8); - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(emailAddressItem); - } + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (person.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (person.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -282,7 +256,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("organization"u8); - if(person.Organization.HasValue) + if (person.Organization.HasValue) { writer.WriteStringValue(person.Organization.Value); } @@ -299,7 +273,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(person.RevisionNumber); writer.WritePropertyName("role"u8); - if(person.Role.HasValue) + if (person.Role.HasValue) { writer.WriteStringValue(person.Role.Value); } @@ -312,31 +286,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - //if (person.TelephoneNumber.Count > 0) - //{ - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(telephoneNumberItem); - } + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("userPreference"u8); - //if (person.UserPreference.Count > 0) - //{ - writer.WriteStartArray("userPreference"u8); - - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(userPreferenceItem); - } + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": @@ -345,7 +311,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); - if(person.DefaultDomain.HasValue) + if (person.DefaultDomain.HasValue) { writer.WriteStringValue(person.DefaultDomain.Value); } @@ -356,7 +322,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultEmailAddress"u8); - if(person.DefaultEmailAddress.HasValue) + if (person.DefaultEmailAddress.HasValue) { writer.WriteStringValue(person.DefaultEmailAddress.Value); } @@ -367,7 +333,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultTelephoneNumber"u8); - if(person.DefaultTelephoneNumber.HasValue) + if (person.DefaultTelephoneNumber.HasValue) { writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } @@ -376,43 +342,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (person.EmailAddress.Count > 0) - //{ - writer.WriteStartArray("emailAddress"u8); + writer.WriteStartArray("emailAddress"u8); - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(emailAddressItem); - } + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (person.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (person.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -426,7 +381,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("organization"u8); - if(person.Organization.HasValue) + if (person.Organization.HasValue) { writer.WriteStringValue(person.Organization.Value); } @@ -443,7 +398,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(person.RevisionNumber); writer.WritePropertyName("role"u8); - if(person.Role.HasValue) + if (person.Role.HasValue) { writer.WriteStringValue(person.Role.Value); } @@ -456,53 +411,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - //if (person.TelephoneNumber.Count > 0) - //{ - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(telephoneNumberItem); - } + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); - //if (person.UserPreference.Count > 0) - //{ - writer.WriteStartArray("userPreference"u8); - - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(userPreferenceItem); - } + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(person.Actor.HasValue) - { - writer.WriteStringValue(person.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(person.ClassKind.ToString()); writer.WritePropertyName("defaultDomain"u8); - if(person.DefaultDomain.HasValue) + if (person.DefaultDomain.HasValue) { writer.WriteStringValue(person.DefaultDomain.Value); } @@ -513,7 +449,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultEmailAddress"u8); - if(person.DefaultEmailAddress.HasValue) + if (person.DefaultEmailAddress.HasValue) { writer.WriteStringValue(person.DefaultEmailAddress.Value); } @@ -524,7 +460,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultTelephoneNumber"u8); - if(person.DefaultTelephoneNumber.HasValue) + if (person.DefaultTelephoneNumber.HasValue) { writer.WriteStringValue(person.DefaultTelephoneNumber.Value); } @@ -533,43 +469,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (person.EmailAddress.Count > 0) - //{ - writer.WriteStartArray("emailAddress"u8); + writer.WriteStartArray("emailAddress"u8); - foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(emailAddressItem); - } + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (person.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (person.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("givenName"u8); writer.WriteStringValue(person.GivenName); @@ -583,7 +508,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("organization"u8); - if(person.Organization.HasValue) + if (person.Organization.HasValue) { writer.WriteStringValue(person.Organization.Value); } @@ -600,7 +525,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(person.RevisionNumber); writer.WritePropertyName("role"u8); - if(person.Role.HasValue) + if (person.Role.HasValue) { writer.WriteStringValue(person.Role.Value); } @@ -613,33 +538,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(person.ShortName); writer.WritePropertyName("surname"u8); writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); - //if (person.TelephoneNumber.Count > 0) - //{ - writer.WriteStartArray("telephoneNumber"u8); - - foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(telephoneNumberItem); - } + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); - //if (person.UserPreference.Count > 0) - //{ - writer.WriteStartArray("userPreference"u8); - - foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(userPreferenceItem); - } + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -649,6 +566,153 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Person person) + { + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -661,32 +725,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -700,11 +758,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultdomain": - if(!AllowedVersionsPerProperty["defaultDomain"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultDomain"u8); if(value != null) @@ -718,11 +771,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultemailaddress": - if(!AllowedVersionsPerProperty["defaultEmailAddress"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultEmailAddress"u8); if(value != null) @@ -736,11 +784,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaulttelephonenumber": - if(!AllowedVersionsPerProperty["defaultTelephoneNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultTelephoneNumber"u8); if(value != null) @@ -754,11 +797,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "emailaddress": - if(!AllowedVersionsPerProperty["emailAddress"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -776,11 +814,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -798,11 +831,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -820,11 +848,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "givenname": - if(!AllowedVersionsPerProperty["givenName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("givenName"u8); if(value != null) @@ -838,11 +861,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -856,11 +874,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isActive"u8); if(value != null) @@ -874,11 +887,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -892,11 +900,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -910,11 +913,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organization": - if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("organization"u8); if(value != null) @@ -928,11 +926,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "organizationalunit": - if(!AllowedVersionsPerProperty["organizationalUnit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("organizationalUnit"u8); if(value != null) @@ -946,11 +939,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "password": - if(!AllowedVersionsPerProperty["password"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("password"u8); if(value != null) @@ -964,11 +952,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -982,11 +965,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "role": - if(!AllowedVersionsPerProperty["role"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("role"u8); if(value != null) @@ -1000,11 +978,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1018,11 +991,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "surname": - if(!AllowedVersionsPerProperty["surname"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("surname"u8); if(value != null) @@ -1036,11 +1004,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "telephonenumber": - if(!AllowedVersionsPerProperty["telephoneNumber"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1058,11 +1021,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1076,11 +1034,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "userpreference": - if(!AllowedVersionsPerProperty["userPreference"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 086e36429..5a2cfbbc6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (point.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (point.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -126,31 +114,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (point.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (point.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -169,44 +149,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(point.Actor.HasValue) - { - writer.WriteStringValue(point.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (point.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (point.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(point.Iid); @@ -230,6 +191,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -242,32 +258,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -281,11 +291,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -303,11 +308,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -325,11 +325,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -343,11 +338,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -361,11 +351,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -379,11 +364,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -397,11 +377,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -415,11 +390,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "x": - if(!AllowedVersionsPerProperty["x"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("x"u8); if(value != null) @@ -433,11 +403,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "y": - if(!AllowedVersionsPerProperty["y"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("y"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index ddf16679b..9941a573a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,37 +77,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteStateList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (possibleFiniteStateList.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); writer.WritePropertyName("defaultState"u8); - if(possibleFiniteStateList.DefaultState.HasValue) + if (possibleFiniteStateList.DefaultState.HasValue) { writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } @@ -120,30 +108,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (possibleFiniteStateList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteStateList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -151,18 +132,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - //if (possibleFiniteStateList.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -171,37 +148,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteStateList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (possibleFiniteStateList.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); writer.WritePropertyName("defaultState"u8); - if(possibleFiniteStateList.DefaultState.HasValue) + if (possibleFiniteStateList.DefaultState.HasValue) { writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } @@ -210,56 +179,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (possibleFiniteStateList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteStateList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -269,18 +223,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - //if (possibleFiniteStateList.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -289,37 +239,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteStateList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (possibleFiniteStateList.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); writer.WritePropertyName("defaultState"u8); - if(possibleFiniteStateList.DefaultState.HasValue) + if (possibleFiniteStateList.DefaultState.HasValue) { writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } @@ -328,56 +270,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (possibleFiniteStateList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteStateList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -387,18 +314,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - //if (possibleFiniteStateList.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -409,47 +332,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(possibleFiniteStateList.Actor.HasValue) + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(possibleFiniteStateList.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (possibleFiniteStateList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (possibleFiniteStateList.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); writer.WritePropertyName("defaultState"u8); - if(possibleFiniteStateList.DefaultState.HasValue) + if (possibleFiniteStateList.DefaultState.HasValue) { writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); } @@ -458,56 +363,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (possibleFiniteStateList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); + writer.WriteStartArray("definition"u8); - foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteStateList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteStateList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteStateList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteStateList.Iid); @@ -517,18 +407,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(possibleFiniteStateList.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); - //if (possibleFiniteStateList.PossibleState.Count > 0) - //{ - writer.WriteStartArray("possibleState"u8); - - foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(possibleStateItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); @@ -544,6 +430,120 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -556,32 +556,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +610,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -639,11 +623,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultstate": - if(!AllowedVersionsPerProperty["defaultState"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultState"u8); if(value != null) @@ -657,11 +636,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -679,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -701,11 +670,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -723,11 +687,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -745,11 +704,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -763,11 +717,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -781,11 +730,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -799,11 +743,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -817,11 +756,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblestate": - if(!AllowedVersionsPerProperty["possibleState"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -839,11 +773,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -857,11 +786,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -875,11 +799,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index f5599ec6c..e80019dd3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteState.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (possibleFiniteState.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteState.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -133,72 +117,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteState.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (possibleFiniteState.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteState.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -213,72 +177,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (possibleFiniteState.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (possibleFiniteState.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteState.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -295,82 +239,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(possibleFiniteState.Actor.HasValue) + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(possibleFiniteState.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (possibleFiniteState.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (possibleFiniteState.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (possibleFiniteState.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (possibleFiniteState.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (possibleFiniteState.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(possibleFiniteState.Iid); @@ -392,6 +306,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not PossibleFiniteState possibleFiniteState) + { + throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -404,32 +400,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -447,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -465,11 +450,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -487,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -509,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -531,11 +501,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -553,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -571,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -589,11 +544,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -607,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -625,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -643,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index 8baff24a1..b77267edc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (prefixedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (prefixedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (prefixedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -135,72 +119,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (prefixedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (prefixedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (prefixedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (prefixedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (prefixedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -217,72 +181,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (prefixedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (prefixedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (prefixedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (prefixedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (prefixedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -301,82 +245,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(prefixedUnit.Actor.HasValue) - { - writer.WriteStringValue(prefixedUnit.Actor.Value); - } - else + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (prefixedUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (prefixedUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (prefixedUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (prefixedUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (prefixedUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(prefixedUnit.Iid); @@ -400,6 +314,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not PrefixedUnit prefixedUnit) + { + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -412,32 +410,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -455,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -473,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +477,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -517,11 +494,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -539,11 +511,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -561,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -579,11 +541,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -597,11 +554,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -615,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "prefix": - if(!AllowedVersionsPerProperty["prefix"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("prefix"u8); if(value != null) @@ -633,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referenceunit": - if(!AllowedVersionsPerProperty["referenceUnit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referenceUnit"u8); if(value != null) @@ -651,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -669,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index defcf4849..797b1f551 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,33 +81,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); - //if (publication.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); + writer.WriteStartArray("publishedParameter"u8); - //if (publication.PublishedParameter.Count > 0) - //{ - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -122,61 +110,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); - //if (publication.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (publication.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (publication.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); - //if (publication.PublishedParameter.Count > 0) - //{ - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -187,61 +159,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); - //if (publication.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (publication.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (publication.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); - //if (publication.PublishedParameter.Count > 0) - //{ - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -250,76 +206,49 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(publication.Actor.HasValue) - { - writer.WriteStringValue(publication.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(publication.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); - //if (publication.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (publication.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (publication.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(publication.Iid); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); - //if (publication.PublishedParameter.Count > 0) - //{ - writer.WriteStartArray("publishedParameter"u8); - - foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(publishedParameterItem); - } + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(publication.RevisionNumber); @@ -333,6 +262,77 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -345,32 +345,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -384,11 +378,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -402,11 +391,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "domain": - if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -424,11 +408,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -446,11 +425,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -468,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -486,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -504,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "publishedparameter": - if(!AllowedVersionsPerProperty["publishedParameter"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -526,11 +485,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -544,11 +498,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 6313a8919..c70731142 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (quantityKindFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (quantityKindFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (quantityKindFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (quantityKindFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(quantityKindFactor.Actor.HasValue) - { - writer.WriteStringValue(quantityKindFactor.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (quantityKindFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (quantityKindFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(quantityKindFactor.Exponent); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not QuantityKindFactor quantityKindFactor) + { + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "exponent": - if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("exponent"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "quantitykind": - if(!AllowedVersionsPerProperty["quantityKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("quantityKind"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index acba9b4e5..65c145e13 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (ratioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ratioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ratioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -130,18 +114,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ratioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -161,88 +141,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (ratioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (ratioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ratioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ratioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ratioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ratioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -252,18 +208,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ratioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -285,88 +237,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ShortName); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (ratioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (ratioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ratioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ratioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ratioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ratioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -376,18 +304,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ratioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -411,98 +335,64 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (ratioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(ratioScale.Actor.HasValue) - { - writer.WriteStringValue(ratioScale.Actor.Value); - } - else + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (ratioScale.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ratioScale.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ratioScale.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ratioScale.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ratioScale.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ratioScale.Iid); @@ -512,18 +402,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); writer.WritePropertyName("isMinimumInclusive"u8); writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); - //if (ratioScale.MappingToReferenceScale.Count > 0) - //{ - writer.WriteStartArray("mappingToReferenceScale"u8); - - foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(mappingToReferenceScaleItem); - } + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("maximumPermissibleValue"u8); writer.WriteStringValue(ratioScale.MaximumPermissibleValue); @@ -547,18 +433,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ratioScale.ThingPreference); writer.WritePropertyName("unit"u8); writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); - //if (ratioScale.ValueDefinition.Count > 0) - //{ - writer.WriteStartArray("valueDefinition"u8); - - foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueDefinitionItem); - } + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -568,6 +450,126 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RatioScale ratioScale) + { + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -580,32 +582,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -623,11 +619,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -641,11 +632,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -663,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -685,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +683,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -729,11 +700,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -747,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -765,11 +726,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ismaximuminclusive": - if(!AllowedVersionsPerProperty["isMaximumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMaximumInclusive"u8); if(value != null) @@ -783,11 +739,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isminimuminclusive": - if(!AllowedVersionsPerProperty["isMinimumInclusive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isMinimumInclusive"u8); if(value != null) @@ -801,11 +752,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "mappingtoreferencescale": - if(!AllowedVersionsPerProperty["mappingToReferenceScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -823,11 +769,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "maximumpermissiblevalue": - if(!AllowedVersionsPerProperty["maximumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maximumPermissibleValue"u8); if(value != null) @@ -841,11 +782,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minimumpermissiblevalue": - if(!AllowedVersionsPerProperty["minimumPermissibleValue"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minimumPermissibleValue"u8); if(value != null) @@ -859,11 +795,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -877,11 +808,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -895,11 +821,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "negativevalueconnotation": - if(!AllowedVersionsPerProperty["negativeValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("negativeValueConnotation"u8); if(value != null) @@ -913,11 +834,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "numberset": - if(!AllowedVersionsPerProperty["numberSet"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("numberSet"u8); if(value != null) @@ -931,11 +847,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "positivevalueconnotation": - if(!AllowedVersionsPerProperty["positiveValueConnotation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("positiveValueConnotation"u8); if(value != null) @@ -949,11 +860,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -967,11 +873,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -985,11 +886,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1003,11 +899,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) @@ -1021,11 +912,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuedefinition": - if(!AllowedVersionsPerProperty["valueDefinition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index 007650018..cd9c412ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (referenceSource.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); - //if (referenceSource.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referenceSource.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referenceSource.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -147,7 +127,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.Name); writer.WritePropertyName("publicationYear"u8); - if(referenceSource.PublicationYear.HasValue) + if (referenceSource.PublicationYear.HasValue) { writer.WriteNumberValue(referenceSource.PublicationYear.Value); } @@ -158,7 +138,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publishedIn"u8); - if(referenceSource.PublishedIn.HasValue) + if (referenceSource.PublishedIn.HasValue) { writer.WriteStringValue(referenceSource.PublishedIn.Value); } @@ -169,7 +149,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publisher"u8); - if(referenceSource.Publisher.HasValue) + if (referenceSource.Publisher.HasValue) { writer.WriteStringValue(referenceSource.Publisher.Value); } @@ -184,7 +164,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.ShortName); writer.WritePropertyName("versionDate"u8); - if(referenceSource.VersionDate.HasValue) + if (referenceSource.VersionDate.HasValue) { writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -198,87 +178,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (referenceSource.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); - //if (referenceSource.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referenceSource.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referenceSource.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referenceSource.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referenceSource.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -292,7 +248,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.Name); writer.WritePropertyName("publicationYear"u8); - if(referenceSource.PublicationYear.HasValue) + if (referenceSource.PublicationYear.HasValue) { writer.WriteNumberValue(referenceSource.PublicationYear.Value); } @@ -303,7 +259,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publishedIn"u8); - if(referenceSource.PublishedIn.HasValue) + if (referenceSource.PublishedIn.HasValue) { writer.WriteStringValue(referenceSource.PublishedIn.Value); } @@ -314,7 +270,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publisher"u8); - if(referenceSource.Publisher.HasValue) + if (referenceSource.Publisher.HasValue) { writer.WriteStringValue(referenceSource.Publisher.Value); } @@ -329,7 +285,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.ShortName); writer.WritePropertyName("versionDate"u8); - if(referenceSource.VersionDate.HasValue) + if (referenceSource.VersionDate.HasValue) { writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -343,87 +299,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (referenceSource.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); - //if (referenceSource.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referenceSource.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referenceSource.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referenceSource.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referenceSource.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -437,7 +369,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.Name); writer.WritePropertyName("publicationYear"u8); - if(referenceSource.PublicationYear.HasValue) + if (referenceSource.PublicationYear.HasValue) { writer.WriteNumberValue(referenceSource.PublicationYear.Value); } @@ -448,7 +380,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publishedIn"u8); - if(referenceSource.PublishedIn.HasValue) + if (referenceSource.PublishedIn.HasValue) { writer.WriteStringValue(referenceSource.PublishedIn.Value); } @@ -459,7 +391,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publisher"u8); - if(referenceSource.Publisher.HasValue) + if (referenceSource.Publisher.HasValue) { writer.WriteStringValue(referenceSource.Publisher.Value); } @@ -476,7 +408,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.ThingPreference); writer.WritePropertyName("versionDate"u8); - if(referenceSource.VersionDate.HasValue) + if (referenceSource.VersionDate.HasValue) { writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -490,97 +422,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(referenceSource.Actor.HasValue) - { - writer.WriteStringValue(referenceSource.Actor.Value); - } - else + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (referenceSource.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); - //if (referenceSource.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referenceSource.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referenceSource.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referenceSource.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referenceSource.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referenceSource.Iid); @@ -594,7 +492,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.Name); writer.WritePropertyName("publicationYear"u8); - if(referenceSource.PublicationYear.HasValue) + if (referenceSource.PublicationYear.HasValue) { writer.WriteNumberValue(referenceSource.PublicationYear.Value); } @@ -605,7 +503,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publishedIn"u8); - if(referenceSource.PublishedIn.HasValue) + if (referenceSource.PublishedIn.HasValue) { writer.WriteStringValue(referenceSource.PublishedIn.Value); } @@ -616,7 +514,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("publisher"u8); - if(referenceSource.Publisher.HasValue) + if (referenceSource.Publisher.HasValue) { writer.WriteStringValue(referenceSource.Publisher.Value); } @@ -633,7 +531,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referenceSource.ThingPreference); writer.WritePropertyName("versionDate"u8); - if(referenceSource.VersionDate.HasValue) + if (referenceSource.VersionDate.HasValue) { writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -652,6 +550,150 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ReferenceSource referenceSource) + { + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -664,32 +706,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +743,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -725,11 +756,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -747,11 +773,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -765,11 +786,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -787,11 +803,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -809,11 +820,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -831,11 +837,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -853,11 +854,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -871,11 +867,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -889,11 +880,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "language": - if(!AllowedVersionsPerProperty["language"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("language"u8); if(value != null) @@ -907,11 +893,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -925,11 +906,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -943,11 +919,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "publicationyear": - if(!AllowedVersionsPerProperty["publicationYear"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("publicationYear"u8); if(value != null) @@ -961,11 +932,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "publishedin": - if(!AllowedVersionsPerProperty["publishedIn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("publishedIn"u8); if(value != null) @@ -979,11 +945,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "publisher": - if(!AllowedVersionsPerProperty["publisher"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("publisher"u8); if(value != null) @@ -997,11 +958,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1015,11 +971,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1033,11 +984,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1051,11 +997,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "versiondate": - if(!AllowedVersionsPerProperty["versionDate"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("versionDate"u8); if(value != null) @@ -1069,11 +1010,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "versionidentifier": - if(!AllowedVersionsPerProperty["versionIdentifier"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("versionIdentifier"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index 6e9a92986..213ffb49b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (referencerRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referencerRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referencerRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -132,18 +116,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(referencerRule.MinReferenced); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - //if (referencerRule.ReferencedCategory.Count > 0) - //{ - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -154,72 +134,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (referencerRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referencerRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referencerRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referencerRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referencerRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -233,18 +193,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - //if (referencerRule.ReferencedCategory.Count > 0) - //{ - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -255,72 +211,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (referencerRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referencerRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referencerRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referencerRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referencerRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -334,18 +270,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - //if (referencerRule.ReferencedCategory.Count > 0) - //{ - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -358,82 +290,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(referencerRule.Actor.HasValue) + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(referencerRule.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (referencerRule.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (referencerRule.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (referencerRule.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (referencerRule.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (referencerRule.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(referencerRule.Iid); @@ -447,18 +349,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); - //if (referencerRule.ReferencedCategory.Count > 0) - //{ - writer.WriteStartArray("referencedCategory"u8); - - foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referencedCategoryItem); - } + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("referencingCategory"u8); writer.WriteStringValue(referencerRule.ReferencingCategory); @@ -476,6 +374,106 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -488,32 +486,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -531,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -549,11 +536,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -571,11 +553,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -593,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -615,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -637,11 +604,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -655,11 +617,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -673,11 +630,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "maxreferenced": - if(!AllowedVersionsPerProperty["maxReferenced"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("maxReferenced"u8); if(value != null) @@ -691,11 +643,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "minreferenced": - if(!AllowedVersionsPerProperty["minReferenced"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("minReferenced"u8); if(value != null) @@ -709,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -727,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -745,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedcategory": - if(!AllowedVersionsPerProperty["referencedCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -767,11 +699,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "referencingcategory": - if(!AllowedVersionsPerProperty["referencingCategory"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referencingCategory"u8); if(value != null) @@ -785,11 +712,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -803,11 +725,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -821,11 +738,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index 098223f42..fd56451d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -93,7 +89,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationalExpression.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationalExpression.Scale.HasValue) + if (relationalExpression.Scale.HasValue) { writer.WriteStringValue(relationalExpression.Scale.Value); } @@ -108,31 +104,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationalExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationalExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -146,7 +134,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationalExpression.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationalExpression.Scale.HasValue) + if (relationalExpression.Scale.HasValue) { writer.WriteStringValue(relationalExpression.Scale.Value); } @@ -161,31 +149,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationalExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationalExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -199,7 +179,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationalExpression.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationalExpression.Scale.HasValue) + if (relationalExpression.Scale.HasValue) { writer.WriteStringValue(relationalExpression.Scale.Value); } @@ -214,44 +194,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(relationalExpression.Actor.HasValue) - { - writer.WriteStringValue(relationalExpression.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationalExpression.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationalExpression.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationalExpression.Iid); @@ -265,7 +226,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationalExpression.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationalExpression.Scale.HasValue) + if (relationalExpression.Scale.HasValue) { writer.WriteStringValue(relationalExpression.Scale.Value); } @@ -285,6 +246,71 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RelationalExpression relationalExpression) + { + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -297,32 +323,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -336,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -358,11 +373,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -380,11 +390,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -398,11 +403,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -416,11 +416,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -434,11 +429,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relationaloperator": - if(!AllowedVersionsPerProperty["relationalOperator"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("relationalOperator"u8); if(value != null) @@ -452,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -470,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -488,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -506,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 7862656db..1c261d588 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationshipParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationshipParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -119,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationshipParameterValue.Scale.HasValue) + if (relationshipParameterValue.Scale.HasValue) { writer.WriteStringValue(relationshipParameterValue.Scale.Value); } @@ -134,31 +122,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationshipParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationshipParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -170,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationshipParameterValue.Scale.HasValue) + if (relationshipParameterValue.Scale.HasValue) { writer.WriteStringValue(relationshipParameterValue.Scale.Value); } @@ -185,44 +165,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(relationshipParameterValue.Actor.HasValue) - { - writer.WriteStringValue(relationshipParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (relationshipParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (relationshipParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(relationshipParameterValue.Iid); @@ -234,7 +195,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(relationshipParameterValue.Scale.HasValue) + if (relationshipParameterValue.Scale.HasValue) { writer.WriteStringValue(relationshipParameterValue.Scale.Value); } @@ -254,6 +215,69 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RelationshipParameterValue relationshipParameterValue) + { + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -266,32 +290,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -305,11 +323,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -327,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -349,11 +357,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -367,11 +370,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -385,11 +383,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -403,11 +396,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -421,11 +409,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -439,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -457,11 +435,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 70884182e..e0f0da84b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (requestForDeviation.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); - //if (requestForDeviation.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -117,44 +105,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForDeviation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForDeviation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForDeviation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -166,7 +142,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); } @@ -175,34 +151,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForDeviation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForDeviation.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -211,33 +180,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (requestForDeviation.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); - //if (requestForDeviation.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -247,44 +208,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForDeviation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForDeviation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForDeviation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -296,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); } @@ -305,34 +254,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForDeviation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForDeviation.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -343,43 +285,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(requestForDeviation.Actor.HasValue) + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(requestForDeviation.Actor.Value); + writer.WriteStringValue(approvedByItem); } - else - { - writer.WriteNullValue(); - } - - //if (requestForDeviation.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); - //if (requestForDeviation.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForDeviation.Classification.ToString()); @@ -389,44 +313,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForDeviation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForDeviation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForDeviation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForDeviation.Iid); @@ -438,7 +350,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForDeviation.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForDeviation.PrimaryAnnotatedThing.HasValue) + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); } @@ -447,34 +359,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForDeviation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForDeviation.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForDeviation.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForDeviation.Status.ToString()); @@ -490,6 +395,132 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -502,32 +533,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -545,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -563,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -603,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -621,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -639,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -657,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -679,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -701,11 +686,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -723,11 +703,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -741,11 +716,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -759,11 +729,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -777,11 +742,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -795,11 +755,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -813,11 +768,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -835,11 +785,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -853,11 +798,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -871,11 +811,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -893,11 +828,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -911,11 +841,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -929,11 +854,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index fb3641b13..ad27b73c4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (requestForWaiver.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); - //if (requestForWaiver.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -117,44 +105,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForWaiver.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForWaiver.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForWaiver.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -166,7 +142,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); } @@ -175,34 +151,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForWaiver.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForWaiver.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -211,33 +180,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (requestForWaiver.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); - //if (requestForWaiver.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -247,44 +208,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForWaiver.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForWaiver.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForWaiver.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -296,7 +245,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); } @@ -305,34 +254,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForWaiver.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForWaiver.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -343,43 +285,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(requestForWaiver.Actor.HasValue) + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(requestForWaiver.Actor.Value); + writer.WriteStringValue(approvedByItem); } - else - { - writer.WriteNullValue(); - } - - //if (requestForWaiver.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); - //if (requestForWaiver.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(requestForWaiver.Classification.ToString()); @@ -389,44 +313,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (requestForWaiver.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requestForWaiver.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requestForWaiver.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requestForWaiver.Iid); @@ -438,7 +350,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requestForWaiver.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(requestForWaiver.PrimaryAnnotatedThing.HasValue) + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); } @@ -447,34 +359,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requestForWaiver.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requestForWaiver.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); - //if (requestForWaiver.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(requestForWaiver.Status.ToString()); @@ -490,6 +395,132 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -502,32 +533,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -545,11 +570,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -563,11 +583,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -603,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -621,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -639,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -657,11 +652,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -679,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -701,11 +686,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -723,11 +703,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -741,11 +716,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -759,11 +729,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -777,11 +742,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -795,11 +755,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -813,11 +768,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -835,11 +785,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -853,11 +798,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -871,11 +811,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -893,11 +828,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -911,11 +841,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -929,11 +854,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 2b0396b16..d4b757bc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,50 +77,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (requirement.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirement.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirement.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("group"u8); - if(requirement.Group.HasValue) + if (requirement.Group.HasValue) { writer.WriteStringValue(requirement.Group.Value); } @@ -133,17 +117,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requirement.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -153,31 +134,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirement.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); - //if (requirement.ParametricConstraint.Count > 0) - //{ - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -186,76 +159,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (requirement.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirement.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirement.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("group"u8); - if(requirement.Group.HasValue) + if (requirement.Group.HasValue) { writer.WriteStringValue(requirement.Group.Value); } @@ -264,17 +217,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requirement.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -286,31 +236,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirement.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); - //if (requirement.ParametricConstraint.Count > 0) - //{ - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -319,76 +261,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (requirement.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirement.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirement.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("group"u8); - if(requirement.Group.HasValue) + if (requirement.Group.HasValue) { writer.WriteStringValue(requirement.Group.Value); } @@ -397,17 +319,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requirement.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -419,31 +338,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirement.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); - //if (requirement.ParametricConstraint.Count > 0) - //{ - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -454,86 +365,56 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(requirement.Actor.HasValue) - { - writer.WriteStringValue(requirement.Actor.Value); - } - else + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (requirement.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirement.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirement.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirement.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirement.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("group"u8); - if(requirement.Group.HasValue) + if (requirement.Group.HasValue) { writer.WriteStringValue(requirement.Group.Value); } @@ -542,17 +423,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (requirement.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + writer.WriteStartArray("hyperLink"u8); - foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirement.Iid); @@ -564,31 +442,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirement.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirement.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("parametricConstraint"u8); - //if (requirement.ParametricConstraint.Count > 0) - //{ - writer.WriteStartArray("parametricConstraint"u8); - - foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(parametricConstraintItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirement.RevisionNumber); @@ -604,6 +474,132 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Requirement requirement) + { + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -616,32 +612,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -659,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -681,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -699,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -721,11 +696,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -743,11 +713,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -765,11 +730,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "group": - if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("group"u8); if(value != null) @@ -783,11 +743,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -805,11 +760,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -823,11 +773,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -841,11 +786,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -859,11 +799,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -877,11 +812,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -895,11 +825,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -917,11 +842,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "parametricconstraint": - if(!AllowedVersionsPerProperty["parametricConstraint"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -939,11 +859,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -957,11 +872,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -975,11 +885,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 40497527b..65628d125 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -119,7 +107,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(requirementsContainerParameterValue.Scale.HasValue) + if (requirementsContainerParameterValue.Scale.HasValue) { writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); } @@ -134,31 +122,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -170,7 +150,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(requirementsContainerParameterValue.Scale.HasValue) + if (requirementsContainerParameterValue.Scale.HasValue) { writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); } @@ -185,44 +165,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(requirementsContainerParameterValue.Actor.HasValue) - { - writer.WriteStringValue(requirementsContainerParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsContainerParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsContainerParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsContainerParameterValue.Iid); @@ -234,7 +195,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(requirementsContainerParameterValue.Scale.HasValue) + if (requirementsContainerParameterValue.Scale.HasValue) { writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); } @@ -254,6 +215,69 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) + { + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -266,32 +290,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -305,11 +323,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -327,11 +340,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -349,11 +357,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -367,11 +370,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -385,11 +383,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -403,11 +396,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -421,11 +409,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -439,11 +422,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -457,11 +435,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 91e80788b..5cacb4250 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsGroup.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -148,98 +128,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsGroup.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -249,18 +201,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsGroup.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -269,98 +217,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsGroup.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -370,18 +290,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsGroup.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -392,108 +308,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(requirementsGroup.Actor.HasValue) + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(requirementsGroup.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (requirementsGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsGroup.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsGroup.Iid); @@ -503,18 +381,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsGroup.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsGroup.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsGroup.RevisionNumber); @@ -530,6 +404,120 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -542,32 +530,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -607,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -625,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -647,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -669,11 +631,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -691,11 +648,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "group": - if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -713,11 +665,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -735,11 +682,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -753,11 +695,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -771,11 +708,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -789,11 +721,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -807,11 +734,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -829,11 +751,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -847,11 +764,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -865,11 +777,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 4a15a0bf3..16b93d3ed 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsSpecification.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsSpecification.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsSpecification.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsSpecification.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -143,18 +123,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("requirement"u8); - //if (requirementsSpecification.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -163,98 +139,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsSpecification.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsSpecification.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsSpecification.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsSpecification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsSpecification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsSpecification.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsSpecification.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -266,31 +214,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsSpecification.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); - //if (requirementsSpecification.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -299,98 +239,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (requirementsSpecification.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsSpecification.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsSpecification.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsSpecification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsSpecification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsSpecification.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsSpecification.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -402,31 +314,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsSpecification.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); - //if (requirementsSpecification.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -437,108 +341,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(requirementsSpecification.Actor.HasValue) - { - writer.WriteStringValue(requirementsSpecification.Actor.Value); - } - else + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (requirementsSpecification.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (requirementsSpecification.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (requirementsSpecification.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (requirementsSpecification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (requirementsSpecification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("group"u8); - //if (requirementsSpecification.Group.Count > 0) - //{ - writer.WriteStartArray("group"u8); - - foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(groupItem); - } + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (requirementsSpecification.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(requirementsSpecification.Iid); @@ -550,31 +416,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(requirementsSpecification.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); - //if (requirementsSpecification.ParameterValue.Count > 0) - //{ - writer.WriteStartArray("parameterValue"u8); - - foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterValueItem); - } + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("requirement"u8); - //if (requirementsSpecification.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(requirementsSpecification.RevisionNumber); @@ -590,6 +448,132 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -602,32 +586,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -645,11 +623,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -667,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -685,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +670,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -729,11 +687,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -751,11 +704,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "group": - if(!AllowedVersionsPerProperty["group"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -773,11 +721,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -795,11 +738,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -813,11 +751,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -831,11 +764,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -849,11 +777,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -867,11 +790,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -885,11 +803,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametervalue": - if(!AllowedVersionsPerProperty["parameterValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -907,11 +820,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "requirement": - if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -929,11 +837,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -947,11 +850,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -965,11 +863,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index 8a4c563e5..6b7419133 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,33 +77,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); - //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); - //if (reviewItemDiscrepancy.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -117,44 +105,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (reviewItemDiscrepancy.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -166,7 +142,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); } @@ -175,47 +151,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (reviewItemDiscrepancy.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); - //if (reviewItemDiscrepancy.Solution.Count > 0) - //{ - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); - //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -224,33 +189,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); - //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); - //if (reviewItemDiscrepancy.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -260,44 +217,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (reviewItemDiscrepancy.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -309,7 +254,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); } @@ -318,47 +263,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (reviewItemDiscrepancy.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); - //if (reviewItemDiscrepancy.Solution.Count > 0) - //{ - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); - //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -369,43 +303,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("approvedBy"u8); - if(reviewItemDiscrepancy.Actor.HasValue) + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(reviewItemDiscrepancy.Actor.Value); + writer.WriteStringValue(approvedByItem); } - else - { - writer.WriteNullValue(); - } - - //if (reviewItemDiscrepancy.ApprovedBy.Count > 0) - //{ - writer.WriteStartArray("approvedBy"u8); - foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(approvedByItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); - //if (reviewItemDiscrepancy.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classification"u8); writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); @@ -415,44 +331,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (reviewItemDiscrepancy.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (reviewItemDiscrepancy.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (reviewItemDiscrepancy.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(reviewItemDiscrepancy.Iid); @@ -464,7 +368,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(reviewItemDiscrepancy.Owner); writer.WritePropertyName("primaryAnnotatedThing"u8); - if(reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) { writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); } @@ -473,47 +377,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (reviewItemDiscrepancy.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); + writer.WriteStartArray("relatedThing"u8); - foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); - //if (reviewItemDiscrepancy.Solution.Count > 0) - //{ - writer.WriteStartArray("solution"u8); - - foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(solutionItem); - } + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("sourceAnnotation"u8); - //if (reviewItemDiscrepancy.SourceAnnotation.Count > 0) - //{ - writer.WriteStartArray("sourceAnnotation"u8); - - foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(sourceAnnotationItem); - } + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("status"u8); writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); @@ -529,6 +422,142 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) + { + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -541,32 +570,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "approvedby": - if(!AllowedVersionsPerProperty["approvedBy"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -584,11 +607,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -602,11 +620,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -624,11 +637,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classification": - if(!AllowedVersionsPerProperty["classification"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classification"u8); if(value != null) @@ -642,11 +650,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -660,11 +663,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -678,11 +676,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -696,11 +689,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -718,11 +706,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -740,11 +723,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -762,11 +740,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -780,11 +753,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -798,11 +766,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -816,11 +779,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -834,11 +792,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -852,11 +805,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -874,11 +822,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -892,11 +835,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -910,11 +848,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "solution": - if(!AllowedVersionsPerProperty["solution"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -932,11 +865,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "sourceannotation": - if(!AllowedVersionsPerProperty["sourceAnnotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -954,11 +882,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -972,11 +895,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -990,11 +908,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "title": - if(!AllowedVersionsPerProperty["title"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("title"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index 9431a2b6e..b1f79f78b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (ruleVerificationList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ruleVerificationList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ruleVerificationList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -130,90 +114,66 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - //if (ruleVerificationList.RuleVerification.Count > 0) - //{ - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (ruleVerificationList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ruleVerificationList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleVerificationList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleVerificationList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ruleVerificationList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -225,90 +185,66 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - //if (ruleVerificationList.RuleVerification.Count > 0) - //{ - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (ruleVerificationList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ruleVerificationList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleVerificationList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleVerificationList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ruleVerificationList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -320,18 +256,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - //if (ruleVerificationList.RuleVerification.Count > 0) - //{ - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -340,82 +272,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(ruleVerificationList.Actor.HasValue) + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(ruleVerificationList.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (ruleVerificationList.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (ruleVerificationList.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleVerificationList.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleVerificationList.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (ruleVerificationList.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleVerificationList.Iid); @@ -427,18 +329,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleVerificationList.Owner); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); - //if (ruleVerificationList.RuleVerification.Count > 0) - //{ - writer.WriteStartArray("ruleVerification"u8); - - foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(ruleVerificationItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(ruleVerificationList.ShortName); @@ -452,6 +350,100 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RuleVerificationList ruleVerificationList) + { + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -464,32 +456,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -507,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -525,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +557,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +574,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -631,11 +587,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -649,11 +600,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -667,11 +613,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -685,11 +626,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -703,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "ruleverification": - if(!AllowedVersionsPerProperty["ruleVerification"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -725,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -743,11 +669,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index 3e74e5642..29069aaa5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,18 +85,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.Iid); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); - //if (ruleViolation.ViolatingThing.Count > 0) - //{ - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": @@ -109,31 +101,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleViolation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleViolation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -141,18 +125,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); - //if (ruleViolation.ViolatingThing.Count > 0) - //{ - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": @@ -161,31 +141,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleViolation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleViolation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -195,62 +167,39 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ruleViolation.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); - //if (ruleViolation.ViolatingThing.Count > 0) - //{ - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(ruleViolation.Actor.HasValue) - { - writer.WriteStringValue(ruleViolation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(ruleViolation.ClassKind.ToString()); writer.WritePropertyName("description"u8); writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); - //if (ruleViolation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (ruleViolation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(ruleViolation.Iid); @@ -260,18 +209,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(ruleViolation.RevisionNumber); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); - //if (ruleViolation.ViolatingThing.Count > 0) - //{ - writer.WriteStartArray("violatingThing"u8); - - foreach(var violatingThingItem in ruleViolation.ViolatingThing) - { - writer.WriteStringValue(violatingThingItem); - } + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -281,6 +226,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -293,32 +299,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -332,11 +332,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "description": - if(!AllowedVersionsPerProperty["description"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("description"u8); if(value != null) @@ -350,11 +345,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -372,11 +362,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -466,11 +431,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "violatingthing": - if(!AllowedVersionsPerProperty["violatingThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index 7d88b04bc..c6395dca8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.2.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,50 +77,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (sampledFunctionParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (sampledFunctionParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (sampledFunctionParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("degreeOfInterpolation"u8); - if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) { writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); } @@ -133,71 +117,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (sampledFunctionParameterType.DependentParameterType.Count > 0) - //{ - writer.WriteStartArray("dependentParameterType"u8); + writer.WriteStartArray("dependentParameterType"u8); - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dependentParameterTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (sampledFunctionParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (sampledFunctionParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (sampledFunctionParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); - //if (sampledFunctionParameterType.IndependentParameterType.Count > 0) - //{ - writer.WriteStartArray("independentParameterType"u8); - - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(independentParameterTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -217,60 +182,38 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(sampledFunctionParameterType.Actor.HasValue) - { - writer.WriteStringValue(sampledFunctionParameterType.Actor.Value); - } - else + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (sampledFunctionParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (sampledFunctionParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (sampledFunctionParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("degreeOfInterpolation"u8); - if(sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) { writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); } @@ -279,71 +222,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (sampledFunctionParameterType.DependentParameterType.Count > 0) - //{ - writer.WriteStartArray("dependentParameterType"u8); + writer.WriteStartArray("dependentParameterType"u8); - foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(dependentParameterTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (sampledFunctionParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (sampledFunctionParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (sampledFunctionParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); - //if (sampledFunctionParameterType.IndependentParameterType.Count > 0) - //{ - writer.WriteStartArray("independentParameterType"u8); - - foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(independentParameterTypeItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); writer.WritePropertyName("isDeprecated"u8); @@ -368,6 +292,133 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -380,32 +431,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -423,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -445,11 +485,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -463,11 +498,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -485,11 +515,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "degreeofinterpolation": - if(!AllowedVersionsPerProperty["degreeOfInterpolation"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("degreeOfInterpolation"u8); if(value != null) @@ -503,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "dependentparametertype": - if(!AllowedVersionsPerProperty["dependentParameterType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -525,11 +545,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -547,11 +562,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -569,11 +579,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +596,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -609,11 +609,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "independentparametertype": - if(!AllowedVersionsPerProperty["independentParameterType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -631,19 +626,9 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "interpolationperiod": - if(!AllowedVersionsPerProperty["interpolationPeriod"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("interpolationPeriod"u8, ((ValueArray)value).ToJsonString()); break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -657,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -675,11 +655,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -693,11 +668,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -711,11 +681,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -729,11 +694,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -747,11 +707,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index 33c7c927a..b0dad7369 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(scaleReferenceQuantityValue.Actor.HasValue) - { - writer.WriteStringValue(scaleReferenceQuantityValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleReferenceQuantityValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleReferenceQuantityValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleReferenceQuantityValue.Iid); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) + { + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("value"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index a79ef7ab7..8c2a1d82b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (scaleValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (scaleValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (scaleValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -135,72 +119,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (scaleValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (scaleValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (scaleValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -217,72 +181,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (scaleValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (scaleValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (scaleValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -301,82 +245,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(scaleValueDefinition.Actor.HasValue) - { - writer.WriteStringValue(scaleValueDefinition.Actor.Value); - } - else + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (scaleValueDefinition.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (scaleValueDefinition.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (scaleValueDefinition.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (scaleValueDefinition.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (scaleValueDefinition.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(scaleValueDefinition.Iid); @@ -400,6 +314,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ScaleValueDefinition scaleValueDefinition) + { + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -412,32 +410,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -455,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -473,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +477,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -517,11 +494,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -539,11 +511,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -561,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -579,11 +541,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -597,11 +554,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -615,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -633,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -651,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -669,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("value"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 1534d61cf..ab2fecd63 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (section.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (section.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (section.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -132,18 +116,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); - //if (section.Page.Count > 0) - //{ - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -152,48 +132,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (section.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (section.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (section.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -203,18 +171,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); - //if (section.Page.Count > 0) - //{ - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -225,58 +189,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(section.Actor.HasValue) - { - writer.WriteStringValue(section.Actor.Value); - } - else + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(categoryItem); } - //if (section.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(section.ClassKind.ToString()); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (section.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (section.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(section.Iid); @@ -286,18 +228,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(section.Name); writer.WritePropertyName("owner"u8); writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); - //if (section.Page.Count > 0) - //{ - writer.WriteStartArray("page"u8); - - foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(pageItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(section.RevisionNumber); @@ -313,6 +251,82 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Section section) + { + throw new ArgumentException("The thing shall be a Section", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -325,32 +339,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -368,11 +376,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -386,11 +389,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -404,11 +402,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -426,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -448,11 +436,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -466,11 +449,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -484,11 +462,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -502,11 +475,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -520,11 +488,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "page": - if(!AllowedVersionsPerProperty["page"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -542,11 +505,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -560,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -578,11 +531,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs index e638d2d62..619ff85f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // @@ -30,6 +30,8 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; + using System.IO; + using System.Text; using System.Text.Json; using CDP4Common; @@ -234,6 +236,63 @@ public static void SerializeClasslessDto(this ClasslessDTO classlessDto, Utf8Jso writer.WriteEndObject(); } + + /// + /// Serialize a into an + /// + /// The + /// A json representation of the + public static string ToJsonString(this Thing thing) + { + if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out var serializer)) + { + throw new NotSupportedException($"The {thing.ClassKind} class is not registered"); + } + + using (var stream = new MemoryStream()) + { + using (var writer = new Utf8JsonWriter(stream)) + { + serializer.Serialize(thing, writer); + writer.Flush(); + stream.Flush(); + return Encoding.UTF8.GetString(stream.ToArray()); + } + } + } + + /// + /// Serialize a into an + /// + /// The + /// A json representation of the + public static string ToJsonString(this ClasslessDTO classlessDto) + { + if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out var serializer)) + { + throw new NotSupportedException($"The {classlessDto["ClassKind"]} class is not registered"); + } + + using (var stream = new MemoryStream()) + { + using (var writer = new Utf8JsonWriter(stream)) + { + writer.WriteStartObject(); + + foreach (var keyValue in classlessDto) + { + var key = Utils.LowercaseFirstLetter(keyValue.Key); + serializer.SerializeProperty(key, keyValue.Value, writer); + } + + writer.WriteEndObject(); + + writer.Flush(); + stream.Flush(); + return Encoding.UTF8.GetString(stream.ToArray()); + } + } + } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index 18eef5fce..b86c85712 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,35 +79,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (sharedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (sharedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(sharedStyle.FillColor.HasValue) + if (sharedStyle.FillColor.HasValue) { writer.WriteStringValue(sharedStyle.FillColor.Value); } @@ -122,7 +110,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(sharedStyle.FillOpacity.HasValue) + if (sharedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.FillOpacity.Value); } @@ -133,7 +121,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(sharedStyle.FontBold.HasValue) + if (sharedStyle.FontBold.HasValue) { writer.WriteBooleanValue(sharedStyle.FontBold.Value); } @@ -144,7 +132,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(sharedStyle.FontColor.HasValue) + if (sharedStyle.FontColor.HasValue) { writer.WriteStringValue(sharedStyle.FontColor.Value); } @@ -155,7 +143,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(sharedStyle.FontItalic.HasValue) + if (sharedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(sharedStyle.FontItalic.Value); } @@ -168,7 +156,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(sharedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(sharedStyle.FontSize.HasValue) + if (sharedStyle.FontSize.HasValue) { writer.WriteNumberValue(sharedStyle.FontSize.Value); } @@ -179,7 +167,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(sharedStyle.FontStrokeThrough.HasValue) + if (sharedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); } @@ -190,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(sharedStyle.FontUnderline.HasValue) + if (sharedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); } @@ -209,7 +197,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(sharedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(sharedStyle.StrokeColor.HasValue) + if (sharedStyle.StrokeColor.HasValue) { writer.WriteStringValue(sharedStyle.StrokeColor.Value); } @@ -220,7 +208,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(sharedStyle.StrokeOpacity.HasValue) + if (sharedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); } @@ -231,7 +219,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(sharedStyle.StrokeWidth.HasValue) + if (sharedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); } @@ -240,52 +228,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (sharedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); + writer.WriteStartArray("usedColor"u8); - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (sharedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (sharedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(sharedStyle.FillColor.HasValue) + if (sharedStyle.FillColor.HasValue) { writer.WriteStringValue(sharedStyle.FillColor.Value); } @@ -296,7 +273,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(sharedStyle.FillOpacity.HasValue) + if (sharedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.FillOpacity.Value); } @@ -307,7 +284,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(sharedStyle.FontBold.HasValue) + if (sharedStyle.FontBold.HasValue) { writer.WriteBooleanValue(sharedStyle.FontBold.Value); } @@ -318,7 +295,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(sharedStyle.FontColor.HasValue) + if (sharedStyle.FontColor.HasValue) { writer.WriteStringValue(sharedStyle.FontColor.Value); } @@ -329,7 +306,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(sharedStyle.FontItalic.HasValue) + if (sharedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(sharedStyle.FontItalic.Value); } @@ -342,7 +319,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(sharedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(sharedStyle.FontSize.HasValue) + if (sharedStyle.FontSize.HasValue) { writer.WriteNumberValue(sharedStyle.FontSize.Value); } @@ -353,7 +330,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(sharedStyle.FontStrokeThrough.HasValue) + if (sharedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); } @@ -364,7 +341,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(sharedStyle.FontUnderline.HasValue) + if (sharedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); } @@ -383,7 +360,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(sharedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(sharedStyle.StrokeColor.HasValue) + if (sharedStyle.StrokeColor.HasValue) { writer.WriteStringValue(sharedStyle.StrokeColor.Value); } @@ -394,7 +371,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(sharedStyle.StrokeOpacity.HasValue) + if (sharedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); } @@ -405,7 +382,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(sharedStyle.StrokeWidth.HasValue) + if (sharedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); } @@ -416,64 +393,41 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); - //if (sharedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(sharedStyle.Actor.HasValue) - { - writer.WriteStringValue(sharedStyle.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (sharedStyle.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (sharedStyle.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("fillColor"u8); - if(sharedStyle.FillColor.HasValue) + if (sharedStyle.FillColor.HasValue) { writer.WriteStringValue(sharedStyle.FillColor.Value); } @@ -484,7 +438,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fillOpacity"u8); - if(sharedStyle.FillOpacity.HasValue) + if (sharedStyle.FillOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.FillOpacity.Value); } @@ -495,7 +449,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontBold"u8); - if(sharedStyle.FontBold.HasValue) + if (sharedStyle.FontBold.HasValue) { writer.WriteBooleanValue(sharedStyle.FontBold.Value); } @@ -506,7 +460,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontColor"u8); - if(sharedStyle.FontColor.HasValue) + if (sharedStyle.FontColor.HasValue) { writer.WriteStringValue(sharedStyle.FontColor.Value); } @@ -517,7 +471,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontItalic"u8); - if(sharedStyle.FontItalic.HasValue) + if (sharedStyle.FontItalic.HasValue) { writer.WriteBooleanValue(sharedStyle.FontItalic.Value); } @@ -530,7 +484,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(sharedStyle.FontName); writer.WritePropertyName("fontSize"u8); - if(sharedStyle.FontSize.HasValue) + if (sharedStyle.FontSize.HasValue) { writer.WriteNumberValue(sharedStyle.FontSize.Value); } @@ -541,7 +495,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontStrokeThrough"u8); - if(sharedStyle.FontStrokeThrough.HasValue) + if (sharedStyle.FontStrokeThrough.HasValue) { writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); } @@ -552,7 +506,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("fontUnderline"u8); - if(sharedStyle.FontUnderline.HasValue) + if (sharedStyle.FontUnderline.HasValue) { writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); } @@ -571,7 +525,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(sharedStyle.RevisionNumber); writer.WritePropertyName("strokeColor"u8); - if(sharedStyle.StrokeColor.HasValue) + if (sharedStyle.StrokeColor.HasValue) { writer.WriteStringValue(sharedStyle.StrokeColor.Value); } @@ -582,7 +536,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeOpacity"u8); - if(sharedStyle.StrokeOpacity.HasValue) + if (sharedStyle.StrokeOpacity.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); } @@ -593,7 +547,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("strokeWidth"u8); - if(sharedStyle.StrokeWidth.HasValue) + if (sharedStyle.StrokeWidth.HasValue) { writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); } @@ -604,18 +558,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); - //if (sharedStyle.UsedColor.Count > 0) - //{ - writer.WriteStartArray("usedColor"u8); - - foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(usedColorItem); - } + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -625,6 +575,190 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SharedStyle sharedStyle) + { + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -637,32 +771,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -676,11 +804,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -698,11 +821,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -720,11 +838,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "fillcolor": - if(!AllowedVersionsPerProperty["fillColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fillColor"u8); if(value != null) @@ -738,11 +851,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fillopacity": - if(!AllowedVersionsPerProperty["fillOpacity"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fillOpacity"u8); if(value != null) @@ -756,11 +864,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontbold": - if(!AllowedVersionsPerProperty["fontBold"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontBold"u8); if(value != null) @@ -774,11 +877,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontcolor": - if(!AllowedVersionsPerProperty["fontColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontColor"u8); if(value != null) @@ -792,11 +890,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontitalic": - if(!AllowedVersionsPerProperty["fontItalic"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontItalic"u8); if(value != null) @@ -810,11 +903,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontname": - if(!AllowedVersionsPerProperty["fontName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontName"u8); if(value != null) @@ -828,11 +916,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontsize": - if(!AllowedVersionsPerProperty["fontSize"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontSize"u8); if(value != null) @@ -846,11 +929,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontstrokethrough": - if(!AllowedVersionsPerProperty["fontStrokeThrough"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontStrokeThrough"u8); if(value != null) @@ -864,11 +942,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "fontunderline": - if(!AllowedVersionsPerProperty["fontUnderline"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("fontUnderline"u8); if(value != null) @@ -882,11 +955,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -900,11 +968,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -918,11 +981,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -936,11 +994,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -954,11 +1007,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokecolor": - if(!AllowedVersionsPerProperty["strokeColor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeColor"u8); if(value != null) @@ -972,11 +1020,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokeopacity": - if(!AllowedVersionsPerProperty["strokeOpacity"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeOpacity"u8); if(value != null) @@ -990,11 +1033,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "strokewidth": - if(!AllowedVersionsPerProperty["strokeWidth"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("strokeWidth"u8); if(value != null) @@ -1008,11 +1046,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1026,11 +1059,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "usedcolor": - if(!AllowedVersionsPerProperty["usedColor"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index b83b4153c..518adc1d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -91,7 +87,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(simpleParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(simpleParameterValue.Scale.HasValue) + if (simpleParameterValue.Scale.HasValue) { writer.WriteStringValue(simpleParameterValue.Scale.Value); } @@ -106,31 +102,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -142,7 +130,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(simpleParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(simpleParameterValue.Scale.HasValue) + if (simpleParameterValue.Scale.HasValue) { writer.WriteStringValue(simpleParameterValue.Scale.Value); } @@ -157,31 +145,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -193,7 +173,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(simpleParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(simpleParameterValue.Scale.HasValue) + if (simpleParameterValue.Scale.HasValue) { writer.WriteStringValue(simpleParameterValue.Scale.Value); } @@ -208,44 +188,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(simpleParameterValue.Actor.HasValue) - { - writer.WriteStringValue(simpleParameterValue.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleParameterValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleParameterValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleParameterValue.Iid); @@ -257,7 +218,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(simpleParameterValue.RevisionNumber); writer.WritePropertyName("scale"u8); - if(simpleParameterValue.Scale.HasValue) + if (simpleParameterValue.Scale.HasValue) { writer.WriteStringValue(simpleParameterValue.Scale.Value); } @@ -277,6 +238,69 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SimpleParameterValue simpleParameterValue) + { + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -289,32 +313,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -328,11 +346,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -350,11 +363,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -372,11 +380,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -390,11 +393,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -408,11 +406,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("parameterType"u8); if(value != null) @@ -426,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -444,11 +432,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("scale"u8); if(value != null) @@ -462,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -480,11 +458,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); break; default: diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index 2749fa947..bd909ed3e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,61 +77,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (simpleQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (simpleQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (simpleQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -143,18 +123,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (simpleQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -167,87 +143,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (simpleQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (simpleQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (simpleQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -257,18 +209,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (simpleQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -281,87 +229,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (simpleQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (simpleQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (simpleQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -371,18 +295,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (simpleQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -397,97 +317,63 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(simpleQuantityKind.Actor.HasValue) + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(simpleQuantityKind.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (simpleQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (simpleQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (simpleQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleQuantityKind.Iid); @@ -497,18 +383,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (simpleQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); @@ -528,6 +410,116 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SimpleQuantityKind simpleQuantityKind) + { + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -540,32 +532,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -583,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -605,11 +586,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -623,11 +599,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultscale": - if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultScale"u8); if(value != null) @@ -641,11 +612,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -663,11 +629,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -685,11 +646,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -707,11 +663,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -729,11 +680,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -747,11 +693,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -765,11 +706,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -783,11 +719,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -801,11 +732,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblescale": - if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -823,11 +749,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "quantitydimensionsymbol": - if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("quantityDimensionSymbol"u8); if(value != null) @@ -841,11 +762,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -859,11 +775,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -877,11 +788,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -895,11 +801,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 437deccc4..aad67d2fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (simpleUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (simpleUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -135,72 +119,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (simpleUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (simpleUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -217,72 +181,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (simpleUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (simpleUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -301,82 +245,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(simpleUnit.Actor.HasValue) - { - writer.WriteStringValue(simpleUnit.Actor.Value); - } - else + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (simpleUnit.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (simpleUnit.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (simpleUnit.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (simpleUnit.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (simpleUnit.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(simpleUnit.Iid); @@ -400,6 +314,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SimpleUnit simpleUnit) + { + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -412,32 +410,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -455,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -473,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +477,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -517,11 +494,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -539,11 +511,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -561,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -579,11 +541,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -597,11 +554,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -615,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -633,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -651,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -669,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index a06e1d759..186132584 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,44 +85,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (siteDirectoryDataAnnotation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -136,18 +120,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); - //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -162,44 +142,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (siteDirectoryDataAnnotation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -209,18 +177,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); - //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -229,17 +193,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryDataAnnotation.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryDataAnnotation.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Author); writer.WritePropertyName("classKind"u8); @@ -248,44 +201,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); - //if (siteDirectoryDataAnnotation.Discussion.Count > 0) - //{ - writer.WriteStartArray("discussion"u8); - - foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(discussionItem); - } + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataAnnotation.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataAnnotation.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); @@ -295,18 +236,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("primaryAnnotatedThing"u8); writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); - //if (siteDirectoryDataAnnotation.RelatedThing.Count > 0) - //{ - writer.WriteStartArray("relatedThing"u8); - - foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(relatedThingItem); - } + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); @@ -320,6 +257,85 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -332,32 +348,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -371,11 +381,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -389,11 +394,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -407,11 +407,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -425,11 +420,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "discussion": - if(!AllowedVersionsPerProperty["discussion"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -447,11 +437,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -469,11 +454,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -491,11 +471,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -509,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -527,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -545,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "primaryannotatedthing": - if(!AllowedVersionsPerProperty["primaryAnnotatedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("primaryAnnotatedThing"u8); if(value != null) @@ -563,11 +523,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "relatedthing": - if(!AllowedVersionsPerProperty["relatedThing"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -585,11 +540,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -603,11 +553,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index a94857204..8ea718a2c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,31 +85,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -123,7 +111,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); } @@ -145,31 +133,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -179,7 +159,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); } @@ -195,17 +175,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryDataDiscussionItem.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryDataDiscussionItem.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); writer.WritePropertyName("classKind"u8); @@ -214,31 +183,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryDataDiscussionItem.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); @@ -248,7 +209,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("replyTo"u8); - if(siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) { writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); } @@ -269,6 +230,74 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -281,32 +310,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -320,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -338,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -356,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -374,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -396,11 +399,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -418,11 +416,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -436,11 +429,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -454,11 +442,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -472,11 +455,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "replyto": - if(!AllowedVersionsPerProperty["replyTo"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("replyTo"u8); if(value != null) @@ -490,11 +468,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -508,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 331b274e0..74a376820 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -87,7 +83,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("defaultParticipantRole"u8); - if(siteDirectory.DefaultParticipantRole.HasValue) + if (siteDirectory.DefaultParticipantRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } @@ -98,7 +94,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultPersonRole"u8); - if(siteDirectory.DefaultPersonRole.HasValue) + if (siteDirectory.DefaultPersonRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); } @@ -107,160 +103,117 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteDirectory.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); + writer.WriteStartArray("domain"u8); - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); - //if (siteDirectory.DomainGroup.Count > 0) - //{ - writer.WriteStartArray("domainGroup"u8); - - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainGroupItem); - } + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (siteDirectory.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); - //if (siteDirectory.Model.Count > 0) - //{ - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modelItem); - } + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - //if (siteDirectory.NaturalLanguage.Count > 0) - //{ - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(naturalLanguageItem); - } + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); - //if (siteDirectory.Organization.Count > 0) - //{ - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationItem); - } + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); - //if (siteDirectory.ParticipantRole.Count > 0) - //{ - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantRoleItem); - } + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); - //if (siteDirectory.Person.Count > 0) - //{ - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personItem); - } + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); - //if (siteDirectory.PersonRole.Count > 0) - //{ - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); - //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - //{ - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); + writer.WriteStartArray("annotation"u8); - //if (siteDirectory.Annotation.Count > 0) - //{ - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(annotationItem); - } + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -268,7 +221,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("defaultParticipantRole"u8); - if(siteDirectory.DefaultParticipantRole.HasValue) + if (siteDirectory.DefaultParticipantRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } @@ -279,7 +232,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultPersonRole"u8); - if(siteDirectory.DefaultPersonRole.HasValue) + if (siteDirectory.DefaultPersonRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); } @@ -288,188 +241,137 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteDirectory.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); + writer.WriteStartArray("domain"u8); - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); - //if (siteDirectory.DomainGroup.Count > 0) - //{ - writer.WriteStartArray("domainGroup"u8); - - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainGroupItem); - } + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectory.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectory.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (siteDirectory.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); - //if (siteDirectory.Model.Count > 0) - //{ - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modelItem); - } + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - //if (siteDirectory.NaturalLanguage.Count > 0) - //{ - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(naturalLanguageItem); - } + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); - //if (siteDirectory.Organization.Count > 0) - //{ - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationItem); - } + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); - //if (siteDirectory.ParticipantRole.Count > 0) - //{ - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantRoleItem); - } + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); - //if (siteDirectory.Person.Count > 0) - //{ - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personItem); - } + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); - //if (siteDirectory.PersonRole.Count > 0) - //{ - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); - //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - //{ - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); + writer.WriteStartArray("annotation"u8); - //if (siteDirectory.Annotation.Count > 0) - //{ - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(annotationItem); - } + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -477,7 +379,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("defaultParticipantRole"u8); - if(siteDirectory.DefaultParticipantRole.HasValue) + if (siteDirectory.DefaultParticipantRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } @@ -488,7 +390,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultPersonRole"u8); - if(siteDirectory.DefaultPersonRole.HasValue) + if (siteDirectory.DefaultPersonRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); } @@ -497,200 +399,139 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteDirectory.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); + writer.WriteStartArray("domain"u8); - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); - //if (siteDirectory.DomainGroup.Count > 0) - //{ - writer.WriteStartArray("domainGroup"u8); - - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainGroupItem); - } + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectory.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectory.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (siteDirectory.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); - //if (siteDirectory.Model.Count > 0) - //{ - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modelItem); - } + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - //if (siteDirectory.NaturalLanguage.Count > 0) - //{ - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(naturalLanguageItem); - } + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); - //if (siteDirectory.Organization.Count > 0) - //{ - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationItem); - } + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); - //if (siteDirectory.ParticipantRole.Count > 0) - //{ - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantRoleItem); - } + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); - //if (siteDirectory.Person.Count > 0) - //{ - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personItem); - } + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); - //if (siteDirectory.PersonRole.Count > 0) - //{ - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); - //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - //{ - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("annotation"u8); - if(siteDirectory.Actor.HasValue) - { - writer.WriteStringValue(siteDirectory.Actor.Value); - } - else + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(annotationItem); } - //if (siteDirectory.Annotation.Count > 0) - //{ - writer.WriteStartArray("annotation"u8); - - foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(annotationItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectory.ClassKind.ToString()); @@ -698,7 +539,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("defaultParticipantRole"u8); - if(siteDirectory.DefaultParticipantRole.HasValue) + if (siteDirectory.DefaultParticipantRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); } @@ -709,181 +550,134 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("defaultPersonRole"u8); - if(siteDirectory.DefaultPersonRole.HasValue) + if (siteDirectory.DefaultPersonRole.HasValue) { writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); } else { - writer.WriteNullValue(); - } - - //if (siteDirectory.Domain.Count > 0) - //{ - writer.WriteStartArray("domain"u8); - - foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainItem); - } - - writer.WriteEndArray(); - //} - + writer.WriteNullValue(); + } - //if (siteDirectory.DomainGroup.Count > 0) - //{ - writer.WriteStartArray("domainGroup"u8); + writer.WriteStartArray("domain"u8); - foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(domainGroupItem); - } + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("domainGroup"u8); - //if (siteDirectory.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectory.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); - writer.WriteEndArray(); - //} + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectory.Iid); writer.WritePropertyName("lastModifiedOn"u8); writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); - //if (siteDirectory.LogEntry.Count > 0) - //{ - writer.WriteStartArray("logEntry"u8); - - foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryItem); - } + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("model"u8); - //if (siteDirectory.Model.Count > 0) - //{ - writer.WriteStartArray("model"u8); - - foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(modelItem); - } + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); - //if (siteDirectory.NaturalLanguage.Count > 0) - //{ - writer.WriteStartArray("naturalLanguage"u8); - - foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(naturalLanguageItem); - } + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("organization"u8); - //if (siteDirectory.Organization.Count > 0) - //{ - writer.WriteStartArray("organization"u8); - - foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(organizationItem); - } + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("participantRole"u8); - //if (siteDirectory.ParticipantRole.Count > 0) - //{ - writer.WriteStartArray("participantRole"u8); - - foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(participantRoleItem); - } + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("person"u8); - //if (siteDirectory.Person.Count > 0) - //{ - writer.WriteStartArray("person"u8); - - foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personItem); - } + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("personRole"u8); - //if (siteDirectory.PersonRole.Count > 0) - //{ - writer.WriteStartArray("personRole"u8); - - foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(personRoleItem); - } + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteDirectory.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); - //if (siteDirectory.SiteReferenceDataLibrary.Count > 0) - //{ - writer.WriteStartArray("siteReferenceDataLibrary"u8); - - foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(siteReferenceDataLibraryItem); - } + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteDirectory.ThingPreference); @@ -895,6 +689,193 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteDirectory siteDirectory) + { + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -907,32 +888,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "annotation": - if(!AllowedVersionsPerProperty["annotation"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -950,11 +925,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -968,11 +938,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -986,11 +951,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultparticipantrole": - if(!AllowedVersionsPerProperty["defaultParticipantRole"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultParticipantRole"u8); if(value != null) @@ -1004,11 +964,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultpersonrole": - if(!AllowedVersionsPerProperty["defaultPersonRole"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultPersonRole"u8); if(value != null) @@ -1022,11 +977,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "domain": - if(!AllowedVersionsPerProperty["domain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1044,11 +994,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "domaingroup": - if(!AllowedVersionsPerProperty["domainGroup"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1066,11 +1011,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1088,11 +1028,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1110,11 +1045,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -1128,11 +1058,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "lastmodifiedon": - if(!AllowedVersionsPerProperty["lastModifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("lastModifiedOn"u8); if(value != null) @@ -1146,11 +1071,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "logentry": - if(!AllowedVersionsPerProperty["logEntry"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1168,11 +1088,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "model": - if(!AllowedVersionsPerProperty["model"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1190,11 +1105,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1208,11 +1118,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -1226,11 +1131,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "naturallanguage": - if(!AllowedVersionsPerProperty["naturalLanguage"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1248,11 +1148,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "organization": - if(!AllowedVersionsPerProperty["organization"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1270,11 +1165,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "participantrole": - if(!AllowedVersionsPerProperty["participantRole"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1292,11 +1182,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "person": - if(!AllowedVersionsPerProperty["person"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1314,11 +1199,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "personrole": - if(!AllowedVersionsPerProperty["personRole"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1336,11 +1216,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1354,11 +1229,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1372,11 +1242,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "sitereferencedatalibrary": - if(!AllowedVersionsPerProperty["siteReferenceDataLibrary"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1394,11 +1259,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 777a9d191..06fd4e6a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,31 +79,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -124,31 +112,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -165,44 +145,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(siteDirectoryThingReference.Actor.HasValue) - { - writer.WriteStringValue(siteDirectoryThingReference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (siteDirectoryThingReference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteDirectoryThingReference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteDirectoryThingReference.Iid); @@ -224,6 +185,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) + { + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -236,32 +250,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -275,11 +283,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -297,11 +300,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -319,11 +317,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -337,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -355,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedrevisionnumber": - if(!AllowedVersionsPerProperty["referencedRevisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referencedRevisionNumber"u8); if(value != null) @@ -373,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "referencedthing": - if(!AllowedVersionsPerProperty["referencedThing"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("referencedThing"u8); if(value != null) @@ -391,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -409,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index c7db63bac..a03bad466 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,35 +77,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (siteLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (siteLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(siteLogEntry.Author.HasValue) + if (siteLogEntry.Author.HasValue) { writer.WriteStringValue(siteLogEntry.Author.Value); } @@ -118,17 +106,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -147,35 +132,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (siteLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (siteLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(siteLogEntry.Author.HasValue) + if (siteLogEntry.Author.HasValue) { writer.WriteStringValue(siteLogEntry.Author.Value); } @@ -184,17 +161,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -202,31 +176,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -241,35 +207,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); - //if (siteLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (siteLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(siteLogEntry.Author.HasValue) + if (siteLogEntry.Author.HasValue) { writer.WriteStringValue(siteLogEntry.Author.Value); } @@ -278,17 +236,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -296,31 +251,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -328,18 +275,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - //if (siteLogEntry.LogEntryChangelogItem.Count > 0) - //{ - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryChangelogItemItem); - } + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -350,45 +293,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("affectedDomainIid"u8); - if(siteLogEntry.Actor.HasValue) + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) { - writer.WriteStringValue(siteLogEntry.Actor.Value); + writer.WriteStringValue(affectedDomainIidItem); } - else - { - writer.WriteNullValue(); - } - - //if (siteLogEntry.AffectedDomainIid.Count > 0) - //{ - writer.WriteStartArray("affectedDomainIid"u8); - foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) - { - writer.WriteStringValue(affectedDomainIidItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("affectedItemIid"u8); - //if (siteLogEntry.AffectedItemIid.Count > 0) - //{ - writer.WriteStartArray("affectedItemIid"u8); - - foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) - { - writer.WriteStringValue(affectedItemIidItem); - } + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("author"u8); - if(siteLogEntry.Author.HasValue) + if (siteLogEntry.Author.HasValue) { writer.WriteStringValue(siteLogEntry.Author.Value); } @@ -397,17 +322,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNullValue(); } - //if (siteLogEntry.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); + writer.WriteStartArray("category"u8); - foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); @@ -415,31 +337,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (siteLogEntry.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteLogEntry.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteLogEntry.Iid); @@ -447,18 +361,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteLogEntry.LanguageCode); writer.WritePropertyName("level"u8); writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); - //if (siteLogEntry.LogEntryChangelogItem.Count > 0) - //{ - writer.WriteStartArray("logEntryChangelogItem"u8); - - foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(logEntryChangelogItemItem); - } + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("modifiedOn"u8); writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); @@ -474,6 +384,112 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -486,32 +502,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "affecteddomainiid": - if(!AllowedVersionsPerProperty["affectedDomainIid"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -529,11 +539,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "affecteditemiid": - if(!AllowedVersionsPerProperty["affectedItemIid"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -551,11 +556,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -569,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +586,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -609,11 +599,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -627,11 +612,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -645,11 +625,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -667,11 +642,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -689,11 +659,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -707,11 +672,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -725,11 +685,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "level": - if(!AllowedVersionsPerProperty["level"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("level"u8); if(value != null) @@ -743,11 +698,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "logentrychangelogitem": - if(!AllowedVersionsPerProperty["logEntryChangelogItem"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -765,11 +715,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -783,11 +728,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -801,11 +741,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index f5c1c634b..2b51a69a7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,124 +77,88 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (siteReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (siteReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (siteReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (siteReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (siteReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (siteReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (siteReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -206,35 +166,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (siteReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + if (siteReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } @@ -245,207 +197,147 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (siteReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (siteReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - //if (siteReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (siteReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (siteReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (siteReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (siteReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (siteReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (siteReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (siteReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -455,35 +347,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (siteReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + if (siteReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } @@ -494,207 +378,147 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (siteReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (siteReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); - //if (siteReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (siteReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (siteReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (siteReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (siteReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (siteReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (siteReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (siteReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -704,35 +528,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (siteReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + if (siteReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } @@ -743,219 +559,149 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (siteReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (siteReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); - //if (siteReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(siteReferenceDataLibrary.Actor.HasValue) + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(siteReferenceDataLibrary.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (siteReferenceDataLibrary.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseQuantityKind"u8); - //if (siteReferenceDataLibrary.BaseQuantityKind.Count > 0) - //{ - writer.WriteStartArray("baseQuantityKind"u8); - - foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) - { + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { writer.WriteOrderedItem(baseQuantityKindItem); - } + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("baseUnit"u8); - //if (siteReferenceDataLibrary.BaseUnit.Count > 0) - //{ - writer.WriteStartArray("baseUnit"u8); - - foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(baseUnitItem); - } + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); - //if (siteReferenceDataLibrary.Constant.Count > 0) - //{ - writer.WriteStartArray("constant"u8); - - foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(constantItem); - } - - writer.WriteEndArray(); - //} - - - //if (siteReferenceDataLibrary.DefinedCategory.Count > 0) - //{ - writer.WriteStartArray("definedCategory"u8); - - foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definedCategoryItem); - } + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definedCategory"u8); - //if (siteReferenceDataLibrary.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("definition"u8); - //if (siteReferenceDataLibrary.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (siteReferenceDataLibrary.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (siteReferenceDataLibrary.FileType.Count > 0) - //{ - writer.WriteStartArray("fileType"u8); - - foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(fileTypeItem); - } + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("fileType"u8); - //if (siteReferenceDataLibrary.Glossary.Count > 0) - //{ - writer.WriteStartArray("glossary"u8); - - foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(glossaryItem); - } + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("glossary"u8); - //if (siteReferenceDataLibrary.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } - foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); - writer.WriteEndArray(); - //} + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(siteReferenceDataLibrary.Iid); @@ -965,35 +711,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); - //if (siteReferenceDataLibrary.ParameterType.Count > 0) - //{ - writer.WriteStartArray("parameterType"u8); - - foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(parameterTypeItem); - } + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("referenceSource"u8); - //if (siteReferenceDataLibrary.ReferenceSource.Count > 0) - //{ - writer.WriteStartArray("referenceSource"u8); - - foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(referenceSourceItem); - } + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("requiredRdl"u8); - if(siteReferenceDataLibrary.RequiredRdl.HasValue) + if (siteReferenceDataLibrary.RequiredRdl.HasValue) { writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); } @@ -1004,61 +742,45 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); - //if (siteReferenceDataLibrary.Rule.Count > 0) - //{ - writer.WriteStartArray("rule"u8); - - foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(ruleItem); - } + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("scale"u8); - //if (siteReferenceDataLibrary.Scale.Count > 0) - //{ - writer.WriteStartArray("scale"u8); - - foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(scaleItem); - } + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(siteReferenceDataLibrary.ShortName); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); - //if (siteReferenceDataLibrary.Unit.Count > 0) - //{ - writer.WriteStartArray("unit"u8); - - foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitItem); - } + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("unitPrefix"u8); - //if (siteReferenceDataLibrary.UnitPrefix.Count > 0) - //{ - writer.WriteStartArray("unitPrefix"u8); - - foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(unitPrefixItem); - } + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -1068,6 +790,221 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -1080,32 +1017,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1123,11 +1054,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "basequantitykind": - if(!AllowedVersionsPerProperty["baseQuantityKind"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1145,11 +1071,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "baseunit": - if(!AllowedVersionsPerProperty["baseUnit"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1167,11 +1088,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -1185,11 +1101,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "constant": - if(!AllowedVersionsPerProperty["constant"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1207,11 +1118,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definedcategory": - if(!AllowedVersionsPerProperty["definedCategory"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1229,11 +1135,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1251,11 +1152,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1273,11 +1169,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1295,11 +1186,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "filetype": - if(!AllowedVersionsPerProperty["fileType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1317,11 +1203,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "glossary": - if(!AllowedVersionsPerProperty["glossary"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1339,11 +1220,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1361,11 +1237,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -1379,11 +1250,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -1397,11 +1263,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -1415,11 +1276,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -1433,11 +1289,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "parametertype": - if(!AllowedVersionsPerProperty["parameterType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1455,11 +1306,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "referencesource": - if(!AllowedVersionsPerProperty["referenceSource"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1477,11 +1323,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "requiredrdl": - if(!AllowedVersionsPerProperty["requiredRdl"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("requiredRdl"u8); if(value != null) @@ -1495,11 +1336,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -1513,11 +1349,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rule": - if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1535,11 +1366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "scale": - if(!AllowedVersionsPerProperty["scale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1557,11 +1383,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -1575,11 +1396,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -1593,11 +1409,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -1615,11 +1426,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "unitprefix": - if(!AllowedVersionsPerProperty["unitPrefix"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 399e1e782..2101aa46b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,31 +85,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (solution.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (solution.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -136,31 +124,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (solution.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (solution.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -177,17 +157,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(solution.Actor.HasValue) - { - writer.WriteStringValue(solution.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("author"u8); writer.WriteStringValue(solution.Author); writer.WritePropertyName("classKind"u8); @@ -196,31 +165,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(solution.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (solution.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (solution.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(solution.Iid); @@ -242,6 +203,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Solution solution) + { + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -254,32 +274,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "author": - if(!AllowedVersionsPerProperty["author"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("author"u8); if(value != null) @@ -293,11 +307,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -311,11 +320,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -329,11 +333,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -347,11 +346,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -369,11 +363,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -391,11 +380,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -409,11 +393,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -427,11 +406,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -445,11 +419,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -463,11 +432,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -481,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index f25bf5694..ccbee4fa9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,63 +77,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (specializedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (specializedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (specializedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - //if (specializedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -145,18 +125,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (specializedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -169,89 +145,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (specializedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (specializedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (specializedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (specializedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (specializedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - //if (specializedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -261,18 +213,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (specializedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -285,89 +233,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (specializedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (specializedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (specializedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (specializedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (specializedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - //if (specializedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -377,18 +301,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (specializedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -403,99 +323,65 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(specializedQuantityKind.Actor.HasValue) + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(specializedQuantityKind.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (specializedQuantityKind.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (specializedQuantityKind.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); writer.WritePropertyName("defaultScale"u8); writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); - //if (specializedQuantityKind.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (specializedQuantityKind.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (specializedQuantityKind.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("general"u8); writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); - //if (specializedQuantityKind.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(specializedQuantityKind.Iid); @@ -505,18 +391,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); - //if (specializedQuantityKind.PossibleScale.Count > 0) - //{ - writer.WriteStartArray("possibleScale"u8); - - foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(possibleScaleItem); - } + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("quantityDimensionSymbol"u8); writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); @@ -536,6 +418,118 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -548,32 +542,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -591,11 +579,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -613,11 +596,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -631,11 +609,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "defaultscale": - if(!AllowedVersionsPerProperty["defaultScale"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("defaultScale"u8); if(value != null) @@ -649,11 +622,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -671,11 +639,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -693,11 +656,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -715,11 +673,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "general": - if(!AllowedVersionsPerProperty["general"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("general"u8); if(value != null) @@ -733,11 +686,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -755,11 +703,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -773,11 +716,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -791,11 +729,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -809,11 +742,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -827,11 +755,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "possiblescale": - if(!AllowedVersionsPerProperty["possibleScale"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -849,11 +772,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "quantitydimensionsymbol": - if(!AllowedVersionsPerProperty["quantityDimensionSymbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("quantityDimensionSymbol"u8); if(value != null) @@ -867,11 +785,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -885,11 +798,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -903,11 +811,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -921,11 +824,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 5a61ed4f9..8d7bc5997 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,98 +77,70 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (stakeHolderValueMap.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeHolderValueMap.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeHolderValueMap.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (stakeHolderValueMap.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeHolderValueMap.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -180,157 +148,113 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); - //if (stakeHolderValueMap.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); - //if (stakeHolderValueMap.Settings.Count > 0) - //{ - writer.WriteStartArray("settings"u8); - - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(settingsItem); - } + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeHolderValueMap.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("valueGroup"u8); - //if (stakeHolderValueMap.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (stakeHolderValueMap.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeHolderValueMap.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeHolderValueMap.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (stakeHolderValueMap.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeHolderValueMap.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -338,169 +262,115 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); - //if (stakeHolderValueMap.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); - //if (stakeHolderValueMap.Settings.Count > 0) - //{ - writer.WriteStartArray("settings"u8); - - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(settingsItem); - } + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeHolderValueMap.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); - //if (stakeHolderValueMap.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(stakeHolderValueMap.Actor.HasValue) + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(stakeHolderValueMap.Actor.Value); + writer.WriteStringValue(aliasItem); } - else - { - writer.WriteNullValue(); - } - - //if (stakeHolderValueMap.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeHolderValueMap.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeHolderValueMap.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMap.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMap.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("goal"u8); - //if (stakeHolderValueMap.Goal.Count > 0) - //{ - writer.WriteStartArray("goal"u8); - - foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(goalItem); - } + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeHolderValueMap.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeHolderValueMap.Iid); @@ -508,63 +378,47 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); writer.WritePropertyName("name"u8); writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); - //if (stakeHolderValueMap.Requirement.Count > 0) - //{ - writer.WriteStartArray("requirement"u8); - - foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(requirementItem); - } + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("revisionNumber"u8); writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); - //if (stakeHolderValueMap.Settings.Count > 0) - //{ - writer.WriteStartArray("settings"u8); - - foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(settingsItem); - } + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeHolderValueMap.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); - //if (stakeHolderValueMap.ValueGroup.Count > 0) - //{ - writer.WriteStartArray("valueGroup"u8); - - foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(valueGroupItem); - } + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -574,6 +428,148 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not StakeHolderValueMap stakeHolderValueMap) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -586,32 +582,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -629,11 +619,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -651,11 +636,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -669,11 +649,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -691,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -713,11 +683,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -735,11 +700,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "goal": - if(!AllowedVersionsPerProperty["goal"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -757,11 +717,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -779,11 +734,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -797,11 +747,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -815,11 +760,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -833,11 +773,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "requirement": - if(!AllowedVersionsPerProperty["requirement"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -855,11 +790,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -873,11 +803,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "settings": - if(!AllowedVersionsPerProperty["settings"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -895,11 +820,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -913,11 +833,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "stakeholdervalue": - if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -935,11 +850,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -953,11 +863,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuegroup": - if(!AllowedVersionsPerProperty["valueGroup"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 1a1b43ab0..7b9c485f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -83,35 +79,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("goalToValueGroupRelationship"u8); - if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); } @@ -128,7 +116,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); - if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); } @@ -139,7 +127,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); - if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); } @@ -153,35 +141,27 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("goalToValueGroupRelationship"u8); - if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); } @@ -198,7 +178,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); - if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); } @@ -211,7 +191,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); - if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); } @@ -223,48 +203,29 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(stakeHolderValueMapSettings.Actor.HasValue) - { - writer.WriteStringValue(stakeHolderValueMapSettings.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeHolderValueMapSettings.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeHolderValueMapSettings.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("goalToValueGroupRelationship"u8); - if(stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); } @@ -281,7 +242,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); - if(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); } @@ -294,7 +255,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); - if(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) { writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); } @@ -311,6 +272,87 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not StakeHolderValueMapSettings stakeHolderValueMapSettings) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -323,32 +365,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -362,11 +398,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -384,11 +415,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -406,11 +432,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "goaltovaluegrouprelationship": - if(!AllowedVersionsPerProperty["goalToValueGroupRelationship"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("goalToValueGroupRelationship"u8); if(value != null) @@ -424,11 +445,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -442,11 +458,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -460,11 +471,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -478,11 +484,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "stakeholdervaluetorequirementrelationship": - if(!AllowedVersionsPerProperty["stakeholderValueToRequirementRelationship"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); if(value != null) @@ -496,11 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -514,11 +510,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "valuegrouptostakeholdervaluerelationship": - if(!AllowedVersionsPerProperty["valueGroupToStakeholderValueRelationship"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 31e94d63d..f7331bd3e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,85 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (stakeholder.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholder.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholder.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholder.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -171,101 +143,73 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeholder.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (stakeholder.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholder.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholder.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholder.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -277,113 +221,75 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeholder.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(stakeholder.Actor.HasValue) - { - writer.WriteStringValue(stakeholder.Actor.Value); - } - else + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (stakeholder.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholder.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholder.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholder.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholder.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholder.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholder.Iid); @@ -395,18 +301,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(stakeholder.RevisionNumber); writer.WritePropertyName("shortName"u8); writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); - //if (stakeholder.StakeholderValue.Count > 0) - //{ - writer.WriteStartArray("stakeholderValue"u8); - - foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(stakeholderValueItem); - } + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(stakeholder.ThingPreference); @@ -418,6 +320,108 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Stakeholder stakeholder) + { + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -430,32 +434,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -473,11 +471,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +488,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -513,11 +501,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -535,11 +518,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -557,11 +535,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -579,11 +552,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -601,11 +569,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -619,11 +582,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -637,11 +595,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -655,11 +608,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -673,11 +621,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -691,11 +634,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "stakeholdervalue": - if(!AllowedVersionsPerProperty["stakeholderValue"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -713,11 +651,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 1df68567c..6be382011 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,85 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (stakeholderValue.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholderValue.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholderValue.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholderValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholderValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholderValue.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -174,85 +146,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (stakeholderValue.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholderValue.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholderValue.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholderValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholderValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholderValue.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -269,95 +217,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(stakeholderValue.Actor.HasValue) - { - writer.WriteStringValue(stakeholderValue.Actor.Value); - } - else + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (stakeholderValue.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (stakeholderValue.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (stakeholderValue.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (stakeholderValue.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (stakeholderValue.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (stakeholderValue.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(stakeholderValue.Iid); @@ -379,6 +293,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -391,32 +397,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -434,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -456,11 +451,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -474,11 +464,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -496,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -518,11 +498,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -540,11 +515,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -562,11 +532,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -580,11 +545,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -598,11 +558,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -616,11 +571,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -634,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -652,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index 56b32e3d8..ad7d98781 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -89,49 +85,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(telephoneNumber.RevisionNumber); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); - //if (telephoneNumber.VcardType.Count > 0) - //{ - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (telephoneNumber.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (telephoneNumber.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -141,49 +125,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteNumberValue(telephoneNumber.RevisionNumber); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); - //if (telephoneNumber.VcardType.Count > 0) - //{ - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (telephoneNumber.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (telephoneNumber.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -195,60 +167,37 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(telephoneNumber.ThingPreference); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); - //if (telephoneNumber.VcardType.Count > 0) - //{ - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(telephoneNumber.Actor.HasValue) - { - writer.WriteStringValue(telephoneNumber.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (telephoneNumber.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (telephoneNumber.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(telephoneNumber.Iid); @@ -260,18 +209,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(telephoneNumber.ThingPreference); writer.WritePropertyName("value"u8); writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); - //if (telephoneNumber.VcardType.Count > 0) - //{ - writer.WriteStartArray("vcardType"u8); - - foreach(var vcardTypeItem in telephoneNumber.VcardType) - { - writer.WriteStringValue(vcardTypeItem.ToString()); - } + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); break; default: @@ -281,6 +226,67 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -293,32 +299,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -332,11 +332,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -354,11 +349,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -376,11 +366,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -394,11 +379,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -412,11 +392,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -430,11 +405,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -448,11 +418,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("value"u8); if(value != null) @@ -466,11 +431,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "vcardtype": - if(!AllowedVersionsPerProperty["vcardType"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 0136bd424..e2102fdd6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,46 +77,34 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (term.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (term.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (term.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -135,72 +119,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (term.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (term.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (term.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (term.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (term.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -217,72 +181,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (term.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (term.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (term.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (term.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (term.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -301,82 +245,52 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(term.Actor.HasValue) - { - writer.WriteStringValue(term.Actor.Value); - } - else + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (term.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (term.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (term.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (term.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (term.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(term.Iid); @@ -400,6 +314,90 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not Term term) + { + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -412,32 +410,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -455,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -473,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -495,11 +477,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -517,11 +494,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -539,11 +511,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -561,11 +528,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -579,11 +541,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -597,11 +554,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -615,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -633,11 +580,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -651,11 +593,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -669,11 +606,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index 0970643b9..5f0c86207 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (textParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (textParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (textParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (textParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -150,85 +130,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (textParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (textParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (textParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (textParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (textParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -247,85 +203,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (textParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (textParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (textParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (textParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (textParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -346,95 +278,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(textParameterType.Actor.HasValue) + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(textParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (textParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (textParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (textParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (textParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (textParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textParameterType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not TextParameterType textParameterType) + { + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +601,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index 79653cdc2..6d1c59e8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,18 +77,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); + writer.WriteStartArray("category"u8); - //if (textualNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -100,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (textualNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textualNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -143,18 +127,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); + writer.WriteStartArray("category"u8); - //if (textualNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -162,31 +142,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (textualNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textualNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -207,28 +179,14 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("category"u8); - if(textualNote.Actor.HasValue) + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(textualNote.Actor.Value); + writer.WriteStringValue(categoryItem); } - else - { - writer.WriteNullValue(); - } - - //if (textualNote.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(textualNote.ClassKind.ToString()); @@ -236,31 +194,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(textualNote.Content); writer.WritePropertyName("createdOn"u8); writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); - //if (textualNote.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (textualNote.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(textualNote.Iid); @@ -286,6 +236,76 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not TextualNote textualNote) + { + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -298,32 +318,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -341,11 +355,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -359,11 +368,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "content": - if(!AllowedVersionsPerProperty["content"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("content"u8); if(value != null) @@ -377,11 +381,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "createdon": - if(!AllowedVersionsPerProperty["createdOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("createdOn"u8); if(value != null) @@ -395,11 +394,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -417,11 +411,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -439,11 +428,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -457,11 +441,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "languagecode": - if(!AllowedVersionsPerProperty["languageCode"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("languageCode"u8); if(value != null) @@ -475,11 +454,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -493,11 +467,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -511,11 +480,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "owner": - if(!AllowedVersionsPerProperty["owner"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("owner"u8); if(value != null) @@ -529,11 +493,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -547,11 +506,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -565,11 +519,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index c7c7b521e..5d20fa4b6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,59 +77,43 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (timeOfDayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (timeOfDayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (timeOfDayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (timeOfDayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -150,85 +130,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (timeOfDayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (timeOfDayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (timeOfDayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (timeOfDayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (timeOfDayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (timeOfDayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -247,85 +203,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (timeOfDayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (timeOfDayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (timeOfDayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (timeOfDayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (timeOfDayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (timeOfDayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -346,95 +278,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(timeOfDayParameterType.Actor.HasValue) + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteStringValue(timeOfDayParameterType.Actor.Value); - } - else - { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (timeOfDayParameterType.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (timeOfDayParameterType.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (timeOfDayParameterType.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (timeOfDayParameterType.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (timeOfDayParameterType.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (timeOfDayParameterType.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(timeOfDayParameterType.Iid); @@ -460,6 +358,102 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not TimeOfDayParameterType timeOfDayParameterType) + { + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -472,32 +466,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -515,11 +503,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -537,11 +520,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -555,11 +533,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -577,11 +550,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -599,11 +567,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -621,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -643,11 +601,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -661,11 +614,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -679,11 +627,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -697,11 +640,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -715,11 +653,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -733,11 +666,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -751,11 +679,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "symbol": - if(!AllowedVersionsPerProperty["symbol"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("symbol"u8); if(value != null) @@ -769,11 +692,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index b0a8b580a..9ffe5fd11 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (unitFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (unitFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(unitFactor.Actor.HasValue) - { - writer.WriteStringValue(unitFactor.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (unitFactor.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitFactor.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("exponent"u8); writer.WriteStringValue(unitFactor.Exponent); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not UnitFactor unitFactor) + { + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "exponent": - if(!AllowedVersionsPerProperty["exponent"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("exponent"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "unit": - if(!AllowedVersionsPerProperty["unit"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("unit"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 62cf1e705..0a7155fb2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,48 +77,36 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.0.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); + writer.WriteStartArray("alias"u8); - //if (unitPrefix.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (unitPrefix.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (unitPrefix.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -137,74 +121,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (unitPrefix.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (unitPrefix.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (unitPrefix.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitPrefix.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (unitPrefix.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -221,74 +185,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (unitPrefix.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (unitPrefix.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (unitPrefix.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitPrefix.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (unitPrefix.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -307,84 +251,54 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(unitPrefix.Actor.HasValue) - { - writer.WriteStringValue(unitPrefix.Actor.Value); - } - else + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (unitPrefix.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(unitPrefix.ClassKind.ToString()); writer.WritePropertyName("conversionFactor"u8); writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); - //if (unitPrefix.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (unitPrefix.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (unitPrefix.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (unitPrefix.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(unitPrefix.Iid); @@ -408,6 +322,92 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not UnitPrefix unitPrefix) + { + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -420,32 +420,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -463,11 +457,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -481,11 +470,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "conversionfactor": - if(!AllowedVersionsPerProperty["conversionFactor"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("conversionFactor"u8); if(value != null) @@ -499,11 +483,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -521,11 +500,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -543,11 +517,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -565,11 +534,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -587,11 +551,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -605,11 +564,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isdeprecated": - if(!AllowedVersionsPerProperty["isDeprecated"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isDeprecated"u8); if(value != null) @@ -623,11 +577,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -641,11 +590,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -659,11 +603,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -677,11 +616,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -695,11 +629,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index ba7ad024a..04e53dab7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -96,31 +92,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userPreference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userPreference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -137,31 +125,23 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userPreference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userPreference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -178,44 +158,25 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(userPreference.Actor.HasValue) - { - writer.WriteStringValue(userPreference.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userPreference.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userPreference.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(userPreference.Iid); @@ -237,6 +198,59 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not UserPreference userPreference) + { + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -249,32 +263,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -288,11 +296,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -310,11 +313,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -332,11 +330,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -350,11 +343,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -368,11 +356,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -386,11 +369,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -404,11 +382,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -422,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "value": - if(!AllowedVersionsPerProperty["value"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("value"u8); if(value != null) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index da37d21a2..3e2bfceff 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.0.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -85,7 +81,7 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); writer.WritePropertyName("executedOn"u8); - if(userRuleVerification.ExecutedOn.HasValue) + if (userRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -104,53 +100,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Rule); writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - - //if (userRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.1.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(userRuleVerification.ExecutedOn.HasValue) + if (userRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -171,53 +146,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Rule); writer.WritePropertyName("status"u8); writer.WriteStringValue(userRuleVerification.Status.ToString()); - - //if (userRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.2.0"); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(userRuleVerification.ExecutedOn.HasValue) + if (userRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -240,64 +194,32 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - - //if (userRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.3.0"); - writer.WritePropertyName("actor"u8); - - if(userRuleVerification.Actor.HasValue) - { - writer.WriteStringValue(userRuleVerification.Actor.Value); - } - else - { - writer.WriteNullValue(); - } - writer.WritePropertyName("classKind"u8); writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); - //if (userRuleVerification.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (userRuleVerification.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("executedOn"u8); - if(userRuleVerification.ExecutedOn.HasValue) + if (userRuleVerification.ExecutedOn.HasValue) { writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); } @@ -320,19 +242,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteStringValue(userRuleVerification.Status.ToString()); writer.WritePropertyName("thingPreference"u8); writer.WriteStringValue(userRuleVerification.ThingPreference); - - //if (userRuleVerification.Violation.Count > 0) - //{ - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in userRuleVerification.Violation.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - - writer.WriteEndArray(); - //} - break; default: throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); @@ -341,6 +250,72 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not UserRuleVerification userRuleVerification) + { + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -353,32 +328,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -392,11 +361,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -414,11 +378,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -436,11 +395,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "executedon": - if(!AllowedVersionsPerProperty["executedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("executedOn"u8); if(value != null) @@ -454,11 +408,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -472,11 +421,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "isactive": - if(!AllowedVersionsPerProperty["isActive"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("isActive"u8); if(value != null) @@ -490,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -508,11 +447,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -526,11 +460,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "rule": - if(!AllowedVersionsPerProperty["rule"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("rule"u8); if(value != null) @@ -544,11 +473,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "status": - if(!AllowedVersionsPerProperty["status"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("status"u8); if(value != null) @@ -562,11 +486,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) @@ -578,28 +497,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer.WriteNullValue(); } - break; - case "violation": - if(!AllowedVersionsPerProperty["violation"].Contains(requestedVersion)) - { - return; - } - - if (value == null) - { - break; - } - - if (value is IEnumerable objectListViolation && objectListViolation.Any()) - { - writer.WriteStartArray("violation"u8); - - foreach(var violationItem in objectListViolation.OfType().OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(violationItem); - } - writer.WriteEndArray(); - } break; default: throw new ArgumentException($"The requested property {propertyName} does not exist on the UserRuleVerification"); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index ea2a7fd36..174cbcf24 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -68,10 +68,6 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM if (requestedDataModelVersion < Version.Parse("1.1.0")) { Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); - - writer.WriteStartObject(); - writer.WriteEndObject(); - return; } @@ -81,85 +77,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM { case "1.1.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); - //if (valueGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (valueGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (valueGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (valueGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (valueGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (valueGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -174,85 +146,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.2.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); - //if (valueGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (valueGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (valueGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (valueGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (valueGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (valueGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -269,95 +217,61 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM break; case "1.3.0": Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.3.0"); - writer.WritePropertyName("actor"u8); + writer.WriteStartArray("alias"u8); - if(valueGroup.Actor.HasValue) - { - writer.WriteStringValue(valueGroup.Actor.Value); - } - else + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) { - writer.WriteNullValue(); + writer.WriteStringValue(aliasItem); } - //if (valueGroup.Alias.Count > 0) - //{ - writer.WriteStartArray("alias"u8); - - foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(aliasItem); - } - - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("category"u8); - //if (valueGroup.Category.Count > 0) - //{ - writer.WriteStartArray("category"u8); - - foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(categoryItem); - } + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("classKind"u8); writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); - //if (valueGroup.Definition.Count > 0) - //{ - writer.WriteStartArray("definition"u8); - - foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(definitionItem); - } + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedDomain"u8); - //if (valueGroup.ExcludedDomain.Count > 0) - //{ - writer.WriteStartArray("excludedDomain"u8); - - foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedDomainItem); - } + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("excludedPerson"u8); - //if (valueGroup.ExcludedPerson.Count > 0) - //{ - writer.WriteStartArray("excludedPerson"u8); - - foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(excludedPersonItem); - } + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); + writer.WriteStartArray("hyperLink"u8); - //if (valueGroup.HyperLink.Count > 0) - //{ - writer.WriteStartArray("hyperLink"u8); - - foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) - { - writer.WriteStringValue(hyperLinkItem); - } + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } - writer.WriteEndArray(); - //} + writer.WriteEndArray(); writer.WritePropertyName("iid"u8); writer.WriteStringValue(valueGroup.Iid); @@ -379,6 +293,98 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM writer.WriteEndObject(); } + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) + { + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + + writer.WriteEndObject(); + } + /// /// Serialize a value for a property into a /// @@ -391,32 +397,26 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - switch(propertyName.ToLower()) + if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) { - case "actor": - if(!AllowedVersionsPerProperty["actor"].Contains(requestedVersion)) - { - return; - } + return; + } - writer.WritePropertyName("actor"u8); - - if(value != null) - { - writer.WriteStringValue((Guid)value); - } - else - { - writer.WriteNullValue(); - } + this.SerializeProperty(propertyName, value, writer); + } - break; + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) + { case "alias": - if(!AllowedVersionsPerProperty["alias"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -434,11 +434,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "category": - if(!AllowedVersionsPerProperty["category"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -456,11 +451,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "classkind": - if(!AllowedVersionsPerProperty["classKind"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("classKind"u8); if(value != null) @@ -474,11 +464,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "definition": - if(!AllowedVersionsPerProperty["definition"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -496,11 +481,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludeddomain": - if(!AllowedVersionsPerProperty["excludedDomain"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -518,11 +498,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "excludedperson": - if(!AllowedVersionsPerProperty["excludedPerson"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -540,11 +515,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "hyperlink": - if(!AllowedVersionsPerProperty["hyperLink"].Contains(requestedVersion)) - { - return; - } - if (value == null) { break; @@ -562,11 +532,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter } break; case "iid": - if(!AllowedVersionsPerProperty["iid"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("iid"u8); if(value != null) @@ -580,11 +545,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "modifiedon": - if(!AllowedVersionsPerProperty["modifiedOn"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("modifiedOn"u8); if(value != null) @@ -598,11 +558,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "name": - if(!AllowedVersionsPerProperty["name"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("name"u8); if(value != null) @@ -616,11 +571,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "revisionnumber": - if(!AllowedVersionsPerProperty["revisionNumber"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("revisionNumber"u8); if(value != null) @@ -634,11 +584,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "shortname": - if(!AllowedVersionsPerProperty["shortName"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("shortName"u8); if(value != null) @@ -652,11 +597,6 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter break; case "thingpreference": - if(!AllowedVersionsPerProperty["thingPreference"].Contains(requestedVersion)) - { - return; - } - writer.WritePropertyName("thingPreference"u8); if(value != null) diff --git a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs index 88969c609..c3f80690f 100644 --- a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs +++ b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs @@ -36,6 +36,14 @@ namespace CDP4JsonSerializer /// public interface IThingSerializer { + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer); + /// /// Serialize a value for a property into a /// @@ -45,6 +53,13 @@ public interface IThingSerializer /// The that has been requested for the serialization void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion); + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + void Serialize(Thing thing, Utf8JsonWriter writer); + /// /// Serializes a into an /// From 6f4f4f258e39019c9f57b0ed79c906b5596e250a Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 6 Nov 2024 15:35:25 +0100 Subject: [PATCH 21/34] RHEA -> Starion --- CDP4Dal/DAL/Dal.cs | 4 ++-- CDP4Dal/DAL/IDal.cs | 4 ++-- CDP4Dal/Exceptions/InvalidOperationContainerException.cs | 4 ++-- CDP4Dal/Exceptions/InvalidOperationKindException.cs | 4 ++-- CDP4Dal/Operations/IThingTransaction.cs | 4 ++-- CDP4Dal/Operations/OperationContainer.cs | 4 ++-- CDP4Dal/Operations/OperationKindExtensions.cs | 4 ++-- CDP4Dal/Operations/ThingTransaction.cs | 4 ++-- CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj | 8 ++++---- CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs | 4 ++-- CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs | 4 ++-- .../JsonConverter/PostOperationJsonConverter.cs | 4 ++-- CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs | 6 +++--- .../ActualFiniteStateKindDeserializer.cs | 4 ++-- .../AnnotationApprovalKindDeserializer.cs | 4 ++-- .../AnnotationClassificationKindDeserializer.cs | 4 ++-- .../AnnotationStatusKindDeserializer.cs | 4 ++-- .../BooleanOperatorKindDeserializer.cs | 4 ++-- .../AutoGenEnumDeserializers/ClassKindDeserializer.cs | 4 ++-- .../EngineeringModelKindDeserializer.cs | 4 ++-- .../InterfaceEndKindDeserializer.cs | 4 ++-- .../LogEntryChangelogItemKindDeserializer.cs | 4 ++-- .../AutoGenEnumDeserializers/LogLevelKindDeserializer.cs | 4 ++-- .../LogarithmBaseKindDeserializer.cs | 4 ++-- .../AutoGenEnumDeserializers/NumberSetKindDeserializer.cs | 4 ++-- .../ParameterSwitchKindDeserializer.cs | 4 ++-- .../ParticipantAccessRightKindDeserializer.cs | 4 ++-- .../PersonAccessRightKindDeserializer.cs | 4 ++-- .../RelationalOperatorKindDeserializer.cs | 4 ++-- .../RuleVerificationStatusKindDeserializer.cs | 4 ++-- .../StudyPhaseKindDeserializer.cs | 4 ++-- .../VcardEmailAddressKindDeserializer.cs | 4 ++-- .../VcardTelephoneNumberKindDeserializer.cs | 4 ++-- .../JsonConverter/ThingConverterExtensions.cs | 4 ++-- CDP4JsonSerializer/SerializerOptions.cs | 4 ++-- 35 files changed, 73 insertions(+), 73 deletions(-) diff --git a/CDP4Dal/DAL/Dal.cs b/CDP4Dal/DAL/Dal.cs index 425bf12ed..28c88814b 100644 --- a/CDP4Dal/DAL/Dal.cs +++ b/CDP4Dal/DAL/Dal.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/DAL/IDal.cs b/CDP4Dal/DAL/IDal.cs index 179a49356..3e4c8dd7f 100644 --- a/CDP4Dal/DAL/IDal.cs +++ b/CDP4Dal/DAL/IDal.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs index 3f076b8e8..3a8e2bad5 100644 --- a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Exceptions/InvalidOperationKindException.cs b/CDP4Dal/Exceptions/InvalidOperationKindException.cs index f12cbda67..b616feee3 100644 --- a/CDP4Dal/Exceptions/InvalidOperationKindException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationKindException.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Operations/IThingTransaction.cs b/CDP4Dal/Operations/IThingTransaction.cs index 664098d16..5bdd8f5d0 100644 --- a/CDP4Dal/Operations/IThingTransaction.cs +++ b/CDP4Dal/Operations/IThingTransaction.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Operations/OperationContainer.cs b/CDP4Dal/Operations/OperationContainer.cs index 2b66a7a9b..71cdd1f39 100644 --- a/CDP4Dal/Operations/OperationContainer.cs +++ b/CDP4Dal/Operations/OperationContainer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Operations/OperationKindExtensions.cs b/CDP4Dal/Operations/OperationKindExtensions.cs index f3b75c509..ce7f45cfa 100644 --- a/CDP4Dal/Operations/OperationKindExtensions.cs +++ b/CDP4Dal/Operations/OperationKindExtensions.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4Dal/Operations/ThingTransaction.cs b/CDP4Dal/Operations/ThingTransaction.cs index 8b74fb5c0..9286973e3 100644 --- a/CDP4Dal/Operations/ThingTransaction.cs +++ b/CDP4Dal/Operations/ThingTransaction.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj index d81af2ef6..b61ff4c8f 100644 --- a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj +++ b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj @@ -2,22 +2,22 @@ net47;net471;net472;net48;netstandard2.0;netstandard2.1 - RHEA System S.A. + Starion Group S.A. latest CDP4DalJsonSerializer Community Edition 28.0.0 JsonSerializer for the CDP4DalCommon types - Copyright © RHEA System S.A. + Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime CDP4DalJsonSerializer-CE true - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition + https://github.com/STARIONGROUP/COMET-SDK-Community-Edition true cdp4-icon.png true true snupkg - https://github.com/RHEAGROUP/COMET-SDK-Community-Edition.git + https://github.com/STARIONGROUP/COMET-SDK-Community-Edition.git CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only diff --git a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs index 7e61c9271..477449a51 100644 --- a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs +++ b/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs b/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs index 1a7d927ff..c1a922b9b 100644 --- a/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs +++ b/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs index 37feb0696..c391f0cb3 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs index 2ba7c5a7c..f7422d122 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs @@ -1,7 +1,7 @@ // -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2023 RHEA System S.A. -// +// +// Copyright (c) 2015-2024 Starion Group S.A. +// // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Jaime Bernar // // This file is part of CDP4-SDK Community Edition diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs index f1d450c52..970712ee8 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs index 4102f47fd..2c1aff9ae 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs index d9ae34f96..836f0fa1d 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs index 2448faab9..1c4d194ee 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs index 850f139b5..97fc42971 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs index cca7ec8a5..0403a56ac 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs index d0990d71e..27fb940e2 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs index f8d5372d9..8ada83306 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs index a5be3bc32..a8d2e067b 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs index 96f9c0dbe..cc8236966 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs index 5f132393b..723c97b51 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs index c2305d32f..f3b6a7f83 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs index 1dc6fcd34..c1efbc40b 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs index 451150651..9c22c901a 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs index 331bbf18c..adc1bc8dc 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs index 5cdf396be..d8b29aece 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs index 9f73e8c37..ca6a2c70d 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs index 0bbad8cc7..c96dfcaed 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs index 4fb8c099d..7df59b43e 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs index 9048d9c7d..7bf91ce87 100644 --- a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs index 5dfa81c43..9cee9b2f9 100644 --- a/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs +++ b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // diff --git a/CDP4JsonSerializer/SerializerOptions.cs b/CDP4JsonSerializer/SerializerOptions.cs index ac115c6b1..4f4642708 100644 --- a/CDP4JsonSerializer/SerializerOptions.cs +++ b/CDP4JsonSerializer/SerializerOptions.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 RHEA System S.A. +// +// Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // From 0505162ac95fc72709e15658de7e6f631d88a745 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Mon, 18 Nov 2024 09:38:19 +0100 Subject: [PATCH 22/34] Finetuning and bugfixes --- .../AutoGenDtoSerializer/ActionItemSerializer.cs | 2 +- .../ActualFiniteStateListSerializer.cs | 2 +- .../ActualFiniteStateSerializer.cs | 2 +- .../AutoGenDtoSerializer/AliasSerializer.cs | 2 +- .../AutoGenDtoSerializer/AndExpressionSerializer.cs | 2 +- .../AutoGenDtoSerializer/ApprovalSerializer.cs | 2 +- .../ArrayParameterTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/BinaryNoteSerializer.cs | 2 +- .../BinaryRelationshipRuleSerializer.cs | 2 +- .../BinaryRelationshipSerializer.cs | 2 +- .../AutoGenDtoSerializer/BookSerializer.cs | 2 +- .../BooleanParameterTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/BoundsSerializer.cs | 2 +- .../BuiltInRuleVerificationSerializer.cs | 2 +- .../AutoGenDtoSerializer/CategorySerializer.cs | 2 +- .../AutoGenDtoSerializer/ChangeProposalSerializer.cs | 2 +- .../AutoGenDtoSerializer/ChangeRequestSerializer.cs | 2 +- .../AutoGenDtoSerializer/CitationSerializer.cs | 2 +- .../AutoGenDtoSerializer/ColorSerializer.cs | 2 +- .../AutoGenDtoSerializer/CommonFileStoreSerializer.cs | 2 +- .../CompoundParameterTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/ConstantSerializer.cs | 2 +- .../ContractChangeNoticeSerializer.cs | 2 +- .../AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs | 2 +- .../DateParameterTypeSerializer.cs | 2 +- .../DateTimeParameterTypeSerializer.cs | 2 +- .../DecompositionRuleSerializer.cs | 2 +- .../AutoGenDtoSerializer/DefinitionSerializer.cs | 2 +- .../DependentParameterTypeAssignmentSerializer.cs | 2 +- .../DerivedQuantityKindSerializer.cs | 2 +- .../AutoGenDtoSerializer/DerivedUnitSerializer.cs | 2 +- .../AutoGenDtoSerializer/DiagramCanvasSerializer.cs | 2 +- .../AutoGenDtoSerializer/DiagramEdgeSerializer.cs | 2 +- .../AutoGenDtoSerializer/DiagramObjectSerializer.cs | 2 +- .../AutoGenDtoSerializer/DomainFileStoreSerializer.cs | 2 +- .../DomainOfExpertiseGroupSerializer.cs | 2 +- .../DomainOfExpertiseSerializer.cs | 2 +- .../ElementDefinitionSerializer.cs | 2 +- .../AutoGenDtoSerializer/ElementUsageSerializer.cs | 2 +- .../AutoGenDtoSerializer/EmailAddressSerializer.cs | 2 +- .../EngineeringModelDataDiscussionItemSerializer.cs | 2 +- .../EngineeringModelDataNoteSerializer.cs | 2 +- .../AutoGenDtoSerializer/EngineeringModelSerializer.cs | 2 +- .../EngineeringModelSetupSerializer.cs | 2 +- .../EnumerationParameterTypeSerializer.cs | 2 +- .../EnumerationValueDefinitionSerializer.cs | 2 +- .../ExclusiveOrExpressionSerializer.cs | 2 +- .../ExternalIdentifierMapSerializer.cs | 2 +- .../AutoGenDtoSerializer/FileRevisionSerializer.cs | 2 +- .../AutoGenDtoSerializer/FileSerializer.cs | 2 +- .../AutoGenDtoSerializer/FileTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/FolderSerializer.cs | 2 +- .../AutoGenDtoSerializer/GlossarySerializer.cs | 2 +- .../AutoGenDtoSerializer/GoalSerializer.cs | 2 +- .../AutoGenDtoSerializer/HyperLinkSerializer.cs | 2 +- .../AutoGenDtoSerializer/IdCorrespondenceSerializer.cs | 2 +- .../IndependentParameterTypeAssignmentSerializer.cs | 2 +- .../AutoGenDtoSerializer/IntervalScaleSerializer.cs | 2 +- .../AutoGenDtoSerializer/IterationSerializer.cs | 2 +- .../AutoGenDtoSerializer/IterationSetupSerializer.cs | 2 +- .../LinearConversionUnitSerializer.cs | 2 +- .../LogEntryChangelogItemSerializer.cs | 2 +- .../AutoGenDtoSerializer/LogarithmicScaleSerializer.cs | 2 +- .../MappingToReferenceScaleSerializer.cs | 2 +- .../AutoGenDtoSerializer/ModelLogEntrySerializer.cs | 2 +- .../ModelReferenceDataLibrarySerializer.cs | 2 +- .../ModellingThingReferenceSerializer.cs | 2 +- .../MultiRelationshipRuleSerializer.cs | 2 +- .../MultiRelationshipSerializer.cs | 2 +- .../AutoGenDtoSerializer/NaturalLanguageSerializer.cs | 2 +- .../AutoGenDtoSerializer/NestedElementSerializer.cs | 2 +- .../AutoGenDtoSerializer/NestedParameterSerializer.cs | 2 +- .../AutoGenDtoSerializer/NotExpressionSerializer.cs | 2 +- .../AutoGenDtoSerializer/OptionSerializer.cs | 2 +- .../AutoGenDtoSerializer/OrExpressionSerializer.cs | 2 +- .../AutoGenDtoSerializer/OrdinalScaleSerializer.cs | 2 +- .../AutoGenDtoSerializer/OrganizationSerializer.cs | 2 +- .../OrganizationalParticipantSerializer.cs | 2 +- .../AutoGenDtoSerializer/OwnedStyleSerializer.cs | 2 +- .../AutoGenDtoSerializer/PageSerializer.cs | 2 +- .../AutoGenDtoSerializer/ParameterGroupSerializer.cs | 2 +- .../ParameterOverrideSerializer.cs | 2 +- .../ParameterOverrideValueSetSerializer.cs | 2 +- .../AutoGenDtoSerializer/ParameterSerializer.cs | 2 +- .../ParameterSubscriptionSerializer.cs | 2 +- .../ParameterSubscriptionValueSetSerializer.cs | 2 +- .../ParameterTypeComponentSerializer.cs | 2 +- .../ParameterValueSetSerializer.cs | 2 +- .../ParameterizedCategoryRuleSerializer.cs | 2 +- .../ParametricConstraintSerializer.cs | 2 +- .../ParticipantPermissionSerializer.cs | 2 +- .../AutoGenDtoSerializer/ParticipantRoleSerializer.cs | 2 +- .../AutoGenDtoSerializer/ParticipantSerializer.cs | 2 +- .../AutoGenDtoSerializer/PersonPermissionSerializer.cs | 2 +- .../AutoGenDtoSerializer/PersonRoleSerializer.cs | 2 +- .../AutoGenDtoSerializer/PersonSerializer.cs | 2 +- .../AutoGenDtoSerializer/PointSerializer.cs | 2 +- .../PossibleFiniteStateListSerializer.cs | 2 +- .../PossibleFiniteStateSerializer.cs | 2 +- .../AutoGenDtoSerializer/PrefixedUnitSerializer.cs | 2 +- .../AutoGenDtoSerializer/PublicationSerializer.cs | 2 +- .../QuantityKindFactorSerializer.cs | 2 +- .../AutoGenDtoSerializer/RatioScaleSerializer.cs | 2 +- .../AutoGenDtoSerializer/ReferenceSourceSerializer.cs | 2 +- .../AutoGenDtoSerializer/ReferencerRuleSerializer.cs | 2 +- .../RelationalExpressionSerializer.cs | 2 +- .../RelationshipParameterValueSerializer.cs | 2 +- .../RequestForDeviationSerializer.cs | 2 +- .../AutoGenDtoSerializer/RequestForWaiverSerializer.cs | 2 +- .../AutoGenDtoSerializer/RequirementSerializer.cs | 2 +- .../RequirementsContainerParameterValueSerializer.cs | 2 +- .../RequirementsGroupSerializer.cs | 2 +- .../RequirementsSpecificationSerializer.cs | 2 +- .../ReviewItemDiscrepancySerializer.cs | 2 +- .../RuleVerificationListSerializer.cs | 2 +- .../AutoGenDtoSerializer/RuleViolationSerializer.cs | 2 +- .../SampledFunctionParameterTypeSerializer.cs | 2 +- .../ScaleReferenceQuantityValueSerializer.cs | 2 +- .../ScaleValueDefinitionSerializer.cs | 2 +- .../AutoGenDtoSerializer/SectionSerializer.cs | 2 +- .../AutoGenDtoSerializer/SharedStyleSerializer.cs | 2 +- .../SimpleParameterValueSerializer.cs | 2 +- .../SimpleQuantityKindSerializer.cs | 2 +- .../AutoGenDtoSerializer/SimpleUnitSerializer.cs | 2 +- .../SiteDirectoryDataAnnotationSerializer.cs | 2 +- .../SiteDirectoryDataDiscussionItemSerializer.cs | 2 +- .../AutoGenDtoSerializer/SiteDirectorySerializer.cs | 2 +- .../SiteDirectoryThingReferenceSerializer.cs | 2 +- .../AutoGenDtoSerializer/SiteLogEntrySerializer.cs | 2 +- .../SiteReferenceDataLibrarySerializer.cs | 2 +- .../AutoGenDtoSerializer/SolutionSerializer.cs | 2 +- .../SpecializedQuantityKindSerializer.cs | 2 +- .../StakeHolderValueMapSerializer.cs | 2 +- .../StakeHolderValueMapSettingsSerializer.cs | 2 +- .../AutoGenDtoSerializer/StakeholderSerializer.cs | 2 +- .../AutoGenDtoSerializer/StakeholderValueSerializer.cs | 2 +- .../AutoGenDtoSerializer/TelephoneNumberSerializer.cs | 2 +- .../AutoGenDtoSerializer/TermSerializer.cs | 2 +- .../TextParameterTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/TextualNoteSerializer.cs | 2 +- .../TimeOfDayParameterTypeSerializer.cs | 2 +- .../AutoGenDtoSerializer/UnitFactorSerializer.cs | 2 +- .../AutoGenDtoSerializer/UnitPrefixSerializer.cs | 2 +- .../AutoGenDtoSerializer/UserPreferenceSerializer.cs | 2 +- .../UserRuleVerificationSerializer.cs | 2 +- .../AutoGenDtoSerializer/ValueGroupSerializer.cs | 2 +- CDP4ServicesDal/CdpServicesDal.cs | 10 +++++++++- 147 files changed, 155 insertions(+), 147 deletions(-) diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 05b5f6a2c..5073e320a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -602,7 +602,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index d659dff23..97867f3c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -390,7 +390,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 00401afc1..8b016249e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -299,7 +299,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 864e2ac0b..47f8e6161 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index b00163305..517095f1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -289,7 +289,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index c33692a65..9acb8a5ee 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -282,7 +282,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index b14333457..2a92a61ce 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -578,7 +578,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 777dfff69..903b856bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -319,7 +319,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 47c9d58d4..487e2d6cd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -460,7 +460,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index 65d2e153c..6518815be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -361,7 +361,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index 77116b70e..1d4fdeb0b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -339,7 +339,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index 519f7bc28..b26f86244 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index cee69a24a..6ee68c045 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -274,7 +274,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 9d091d63e..ea17a9ada 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -328,7 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index 7b9033821..e159430a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -512,7 +512,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index 870607ca4..e54c961e7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -541,7 +541,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index e37ceb3c7..308bc002c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -533,7 +533,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index 373db2357..40af0fdb1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -293,7 +293,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 6118ad542..0fe2f658b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -283,7 +283,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 21e542da3..7104c4942 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -365,7 +365,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index 00413de50..7f3dbc595 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -522,7 +522,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index ee6d45fd2..b4425495f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -526,7 +526,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index b25d66857..6cb9fd11a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -541,7 +541,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index 1b6157ce1..ce4d2cb94 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -592,7 +592,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 03c724c3e..760e45790 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index 237a0ad4a..6a4f2e03e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index d2aca878b..15c70da75 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -531,7 +531,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 8f5c73acd..ca8058d46 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -400,7 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index abc688bdf..8e595bd50 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -244,7 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index 0217a3243..34f843a9e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -578,7 +578,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index 6a4d8ab39..5b1d7f0c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index 13d280f91..a6cd44377 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -323,7 +323,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index e19dc97c6..895eb57d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -492,7 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index e9ed53414..8143e6a82 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -455,7 +455,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index a78f18d7a..5f81ab4f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -375,7 +375,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index 62865f963..c9667147f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index 59ad1fe4d..c41b9dbc3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index c38a216cf..b6961ed99 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -668,7 +668,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index e7bf082f4..94f472574 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -568,7 +568,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index 6e15f24a2..bd1163b07 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index 7709b4d2f..b7a0eb433 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -310,7 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 06425018b..154c5b0c1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -383,7 +383,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 8f273acab..5acc4b77f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -511,7 +511,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index 64e5c55ab..c25f19b4b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -729,7 +729,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 4fa334924..7f530a8b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -522,7 +522,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 3806cfcf1..4c23cbca8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -400,7 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index 161c1b59a..d9d3732ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -289,7 +289,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 02ba023de..6ffeb5fc0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -394,7 +394,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 944e0e3a3..5c6333c05 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -384,7 +384,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 785800e6e..4e77b2aad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -399,7 +399,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index d1366a4ad..91c6feffa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 946cc3bc5..7ad26feb4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -338,7 +338,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index efebbeaf7..356b31da8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -502,7 +502,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index daa91005a..5c0edcb97 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -397,7 +397,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 80f1f4e67..7b306e4ba 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index fd465e905..cda931b33 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index d7858bb30..cd10954ea 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -244,7 +244,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 00cf3a169..b3747c45e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -582,7 +582,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index f56e22d25..fc4e243df 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1133,7 +1133,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index 562b4235b..94659870e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -403,7 +403,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 1e16a3a6c..7a02a38ea 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -430,7 +430,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index c55d29bde..e7cef7530 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -251,7 +251,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index f70c4e21d..5c04086d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -668,7 +668,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index 40973d997..8aaddf4f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index bf94029c0..e16d5dd13 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -502,7 +502,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 5dfeb2199..5090210aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1007,7 +1007,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index fb487233d..638d266a4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -250,7 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index 3a8eb4d77..d521b762d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -486,7 +486,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index b34becb36..732b37b4c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -387,7 +387,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index da93a3762..97c4f8f18 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 29dc82cdb..700477336 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -355,7 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index 1f9956a58..c4ba39bb4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -348,7 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 0b69516b8..ea3fb15eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -253,7 +253,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index d677a8aed..462a94291 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -492,7 +492,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index fd8f5752c..c53f2c030 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -289,7 +289,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 2bdd2063c..14c6f5b02 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -592,7 +592,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index b39dc7d71..2111dc5a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 957be2f25..4cec229c8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -211,7 +211,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 2a66a98f6..1c4c03ca2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -771,7 +771,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index c4701de65..d537ba163 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -339,7 +339,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index 1c85ae8d2..aef6bc3f7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -307,7 +307,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 7651356d3..1aaeb7a16 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -355,7 +355,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 7c73970d0..3de5898cf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -288,7 +288,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index f25295cb7..e0f315673 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -605,7 +605,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index e0a587cd5..1f6f3b9f2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -299,7 +299,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 5aaa4c465..01180b858 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -268,7 +268,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 049c4286a..cf56b41e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -318,7 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 5de2a34d9..4f9a06cca 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -388,7 +388,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index e795bb993..8eb7102a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index bc0244fb8..0a34725d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -343,7 +343,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index a2958cfe2..83c426295 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index d7e4c06a7..f3eca8f1e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index e9b2d11ea..dc27bc41e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -329,7 +329,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index 4a50aed63..0de2a6cc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -273,7 +273,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 1f9f019e1..627d79e01 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index d3637c846..24d9f7b85 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -725,7 +725,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 5a2cfbbc6..8e0a4f390 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -258,7 +258,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 9941a573a..7c5b1aa45 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -556,7 +556,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index e80019dd3..cb8f53322 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -400,7 +400,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index b77267edc..dfd6323e3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -410,7 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index 797b1f551..b3ba81a33 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -345,7 +345,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index c70731142..113010aec 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index 65c145e13..169695b8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -582,7 +582,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index cd9c412ab..421178168 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -706,7 +706,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index 213ffb49b..a11d1a27f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -486,7 +486,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index fd56451d8..3c0e5e4f4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -323,7 +323,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 1c261d588..cdb206dde 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -290,7 +290,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index e0f0da84b..099c10c3e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -533,7 +533,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index ad27b73c4..a78bc243e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -533,7 +533,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index d4b757bc0..30c9ab01b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -612,7 +612,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 65628d125..56b76c3a6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -290,7 +290,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 5cacb4250..d4581e74d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -530,7 +530,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 16b93d3ed..ca7ec651d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -586,7 +586,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index 6b7419133..9f2eb119b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -570,7 +570,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index b1f79f78b..edc4da66a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -456,7 +456,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index 29069aaa5..88351483d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -299,7 +299,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index c6395dca8..b28caf532 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -431,7 +431,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index b0dad7369..07f15a290 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index 8c2a1d82b..73f923029 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -410,7 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index ab2fecd63..6b927fe51 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -339,7 +339,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index b86c85712..e143670a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -771,7 +771,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 518adc1d4..2bbac1977 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -313,7 +313,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index bd909ed3e..55a0dc9bf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -532,7 +532,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index aad67d2fa..f38ff1df9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -410,7 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 186132584..10fdeb21c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -348,7 +348,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index 8ea718a2c..712ba3443 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -310,7 +310,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 74a376820..882e37d3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -888,7 +888,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 06fd4e6a9..9cbdbe6a3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -250,7 +250,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index a03bad466..1b4bec2ef 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -502,7 +502,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index 2b51a69a7..c0ebc3cec 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1017,7 +1017,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 2101aa46b..2e9e8cca7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -274,7 +274,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index ccbee4fa9..b5862170f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -542,7 +542,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 8d7bc5997..da44522c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -582,7 +582,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 7b9c485f6..234b07918 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -365,7 +365,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index f7331bd3e..c3c201067 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -434,7 +434,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 6be382011..3a1feeee1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -397,7 +397,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index ad7d98781..4aade4864 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -299,7 +299,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index e2102fdd6..42e15fc06 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -410,7 +410,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index 5f0c86207..a19cafc60 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index 6d1c59e8a..aa7032dc6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -318,7 +318,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index 5d20fa4b6..2af70a333 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -466,7 +466,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 9ffe5fd11..4d93a402c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 0a7155fb2..0b840ce1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -420,7 +420,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 04e53dab7..74bfe286c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -263,7 +263,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index 3e2bfceff..45b9ab8c0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -328,7 +328,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 174cbcf24..57507be25 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -397,7 +397,7 @@ public void SerializeProperty(string propertyName, object value, Utf8JsonWriter { var requestedVersion = requestedDataModelVersion.ToString(3); - if(!AllowedVersionsPerProperty[""].Contains(requestedVersion)) + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { return; } diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index 8d2a32dda..c8f1226dd 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -94,11 +94,19 @@ public class CdpServicesDal : Dal /// private readonly bool isMessagePackSupported; + /// + /// Initializes a new instance of the class. + /// + public CdpServicesDal(): this(true) + { + // Default constructor + } + /// /// Initializes a new instance of the class. /// /// Asserts that the MessagePack deserialization should be used or not. Supported by default - public CdpServicesDal(bool isMessagePackSupported = true) + public CdpServicesDal(bool isMessagePackSupported) { this.Cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); this.MessagePackSerializer = new MessagePackSerializer(); From d0a68eecd0356be2cc4b76d8f8c722155282b17c Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Mon, 18 Nov 2024 09:42:05 +0100 Subject: [PATCH 23/34] update PackageReleaseNotes --- CDP4Common/CDP4Common.csproj | 2 +- CDP4Dal/CDP4Dal.csproj | 2 +- CDP4DalCommon/CDP4DalCommon.csproj | 2 +- CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj | 2 +- CDP4JsonFileDal/CDP4JsonFileDal.csproj | 2 +- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 2 +- CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj | 3 +-- CDP4Reporting/CDP4Reporting.csproj | 2 +- .../CDP4RequirementsVerification.csproj | 2 +- CDP4Rules/CDP4Rules.csproj | 2 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 2 +- CDP4ServicesMessaging/CDP4ServicesMessaging.csproj | 2 +- CDP4Web/CDP4Web.csproj | 3 +-- CDP4WspDal/CDP4WspDal.csproj | 2 +- 14 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CDP4Common/CDP4Common.csproj b/CDP4Common/CDP4Common.csproj index 4e0bcce76..20a4713f0 100644 --- a/CDP4Common/CDP4Common.csproj +++ b/CDP4Common/CDP4Common.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [ADD] SharpZipLibExtension Methods + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index 2546d617f..1b78dc814 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj index a3e4c54ca..8c40d62df 100644 --- a/CDP4DalCommon/CDP4DalCommon.csproj +++ b/CDP4DalCommon/CDP4DalCommon.csproj @@ -21,7 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md true diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj index b61ff4c8f..b24045f1d 100644 --- a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj +++ b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj @@ -21,7 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 26.6.0 + [Refactor] Newtonsoft to System.Text.Json README.md true diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 52faff2c4..0f618bcad 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - - Remove DotNetZip and use SharpZipLib + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 8bc8f9849..e4d59ae43 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 JSON LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md 11.0 diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index 5d4ef7750..7523d28df 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -20,8 +20,7 @@ CDP COMET ECSS-E-TM-10-25 MessagePack LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 - [Update] To MessagePack 2.5.187 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4Reporting/CDP4Reporting.csproj b/CDP4Reporting/CDP4Reporting.csproj index 03f21f677..75d99793c 100644 --- a/CDP4Reporting/CDP4Reporting.csproj +++ b/CDP4Reporting/CDP4Reporting.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json latest README.md diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj index c2fa0ae7b..5b02e3a22 100644 --- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj +++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj index 17116abc5..a36697597 100644 --- a/CDP4Rules/CDP4Rules.csproj +++ b/CDP4Rules/CDP4Rules.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 58b800644..f0387a207 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index 034b83958..f57b6ec90 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md latest diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj index 52679ed94..7f0863519 100644 --- a/CDP4Web/CDP4Web.csproj +++ b/CDP4Web/CDP4Web.csproj @@ -21,8 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 - [Update] to Microsoft.Extensions.Logging.Abstractions 8.0.2 + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index f871a0c2e..308604723 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md From 1936e00af54a424ff03dc4e8f453a3f8a7b5c2ca Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Tue, 19 Nov 2024 17:19:34 +0100 Subject: [PATCH 24/34] MessageBus performance --- CDP4Dal/CDPMessageBus.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CDP4Dal/CDPMessageBus.cs b/CDP4Dal/CDPMessageBus.cs index 61bd21072..ec19823df 100644 --- a/CDP4Dal/CDPMessageBus.cs +++ b/CDP4Dal/CDPMessageBus.cs @@ -57,7 +57,7 @@ public sealed class CDPMessageBus : ICDPMessageBus /// /// The holding the subscriptions. /// - private readonly ConcurrentDictionary> messageBus = new ConcurrentDictionary>(); + private readonly ConcurrentDictionary messageBus = new ConcurrentDictionary(); /// /// Number of currently active Observables in the @@ -124,7 +124,7 @@ private IObservable GetOrAddObservable(EventTypeTarget eventTypeTarget) { var cdpEventSubject = this.messageBus.GetOrAdd( eventTypeTarget, - arg => new Lazy(() => this.ComposeEventSubject(eventTypeTarget))).Value; + this.ComposeEventSubject(eventTypeTarget)); return (IObservable)cdpEventSubject.Observable; } @@ -201,7 +201,7 @@ public void SendMessage(T message, object target = null, string contract = nu if (getObservable) { - ((Subject)cdpEventSubject.Value.Subject).OnNext(message); + ((Subject)cdpEventSubject.Subject).OnNext(message); } } From 91e394a2ea1e6e022fe9c4207bccabec86057906 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 20 Nov 2024 12:08:36 +0100 Subject: [PATCH 25/34] Upgrade references --- CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj | 2 +- CDP4Common.Tests/CDP4Common.Tests.csproj | 2 +- CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj | 2 +- CDP4Dal.Tests/CDP4Dal.Tests.csproj | 2 +- .../CDP4JsonFileDal.NetCore.Tests.csproj | 4 ++-- CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj | 2 +- .../CDP4JsonSerializer.NetCore.Tests.csproj | 2 +- CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj | 2 +- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 2 +- .../CDP4MessagePackSerializer.Tests.csproj | 2 +- .../CDP4MessagePackSerializer.csproj | 4 ++-- CDP4Reporting.Tests/CDP4Reporting.Tests.csproj | 2 +- .../CDP4RequirementsVerification.Tests.csproj | 2 +- CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj | 2 +- .../CDP4ServicesDal.NetCore.Tests.csproj | 2 +- CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj | 2 +- .../CDP4ServicesMessaging.Tests.csproj | 2 +- CDP4ServicesMessaging/CDP4ServicesMessaging.csproj | 8 ++++---- CDP4Web.Tests/CDP4Web.Tests.csproj | 4 ++-- CDP4Web/CDP4Web.csproj | 2 +- CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj | 2 +- CDP4WspDal.Tests/CDP4WspDal.Tests.csproj | 2 +- pre-release.bat | 2 +- 23 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj b/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj index 258bb07ed..a0049ddd5 100644 --- a/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj +++ b/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/CDP4Common.Tests/CDP4Common.Tests.csproj b/CDP4Common.Tests/CDP4Common.Tests.csproj index 643e8d26c..8fbce3656 100644 --- a/CDP4Common.Tests/CDP4Common.Tests.csproj +++ b/CDP4Common.Tests/CDP4Common.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj b/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj index 032f1813d..a8b5dc3de 100644 --- a/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj +++ b/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4Dal.Tests/CDP4Dal.Tests.csproj b/CDP4Dal.Tests/CDP4Dal.Tests.csproj index 9b1f57b17..bda4c0dce 100644 --- a/CDP4Dal.Tests/CDP4Dal.Tests.csproj +++ b/CDP4Dal.Tests/CDP4Dal.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj b/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj index 37be5d683..65118c357 100644 --- a/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj +++ b/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj @@ -17,12 +17,12 @@ - + - + diff --git a/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj b/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj index 329ba1735..2654a5b64 100644 --- a/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj +++ b/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj @@ -22,7 +22,7 @@ - + diff --git a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj index be855025d..ceaef1877 100644 --- a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj +++ b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj b/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj index 7617d3d16..098fc4c00 100644 --- a/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj +++ b/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index e4d59ae43..a95305638 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -29,7 +29,7 @@ - + diff --git a/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj b/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj index debc6f9ae..eef5800a5 100644 --- a/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj +++ b/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index 7523d28df..65b667f6a 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -35,8 +35,8 @@ - - + + diff --git a/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj b/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj index 03c7802a5..c4cdfa36e 100644 --- a/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj +++ b/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj @@ -28,7 +28,7 @@ - + diff --git a/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj b/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj index 3504ebc5a..fd1c7c43d 100644 --- a/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj +++ b/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj b/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj index 0d3a282e1..4e013a92a 100644 --- a/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj +++ b/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj index 30a83b9dc..865cfab69 100644 --- a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj +++ b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj b/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj index 15478becf..7b14022b4 100644 --- a/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj +++ b/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj index 2e36d34d6..5c382bcfd 100644 --- a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj +++ b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index f57b6ec90..c238e3485 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -37,10 +37,10 @@ - - - - + + + + diff --git a/CDP4Web.Tests/CDP4Web.Tests.csproj b/CDP4Web.Tests/CDP4Web.Tests.csproj index 703657985..c6e80e872 100644 --- a/CDP4Web.Tests/CDP4Web.Tests.csproj +++ b/CDP4Web.Tests/CDP4Web.Tests.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj index 7f0863519..4f6000a70 100644 --- a/CDP4Web/CDP4Web.csproj +++ b/CDP4Web/CDP4Web.csproj @@ -39,7 +39,7 @@ - + diff --git a/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj b/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj index 0edea0745..582140888 100644 --- a/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj +++ b/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj b/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj index a90610895..e8c4b5fe2 100644 --- a/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj +++ b/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj @@ -23,7 +23,7 @@ - + diff --git a/pre-release.bat b/pre-release.bat index fdc4863f8..fa4c872bc 100644 --- a/pre-release.bat +++ b/pre-release.bat @@ -44,7 +44,7 @@ ECHO. for %%f in (%~dp0PreReleaseBuilds\*.nupkg) do ( (Echo "%%f" | FIND /I "symbols" 1>NUL) || ( echo Pushing %%f - echo dotnet nuget push "%%f" --source https://nuget.pkg.github.com/RHEAGROUP/index.json -k %apikey% + dotnet nuget push "%%f" --source https://nuget.pkg.github.com/STARIONGROUP/index.json -k %apikey% ) ) From 03573d7b11e1b5d17f3c7bdb2a95864a08865676 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Thu, 21 Nov 2024 15:27:49 +0100 Subject: [PATCH 26/34] Refactor Assembler for better performance --- CDP4Dal/Assembler.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/CDP4Dal/Assembler.cs b/CDP4Dal/Assembler.cs index c96136dca..5b855584d 100644 --- a/CDP4Dal/Assembler.cs +++ b/CDP4Dal/Assembler.cs @@ -143,9 +143,7 @@ public async Task Synchronize(IEnumerable dtoThings, bool logger.Info("Start Synchronization of {0}", this.IDalUri); var existentGuid = - this.Cache.Select( - x => new Tuple(x.Value.Value.CacheKey, x.Value.Value.RevisionNumber)) - .ToList(); + new Dictionary(this.Cache.ToDictionary(x => x.Value.Value.CacheKey, y => y.Value.Value.RevisionNumber)); this.CheckPartitionDependentContainmentContainerIds(dtoThings); @@ -224,17 +222,14 @@ public async Task Synchronize(IEnumerable dtoThings, bool if (succeed) { var thingObject = updatedLazyThing.Value; - var cacheId = new CacheKey(dtoThing.Iid, dtoThing.IterationContainerId); - - if (!existentGuid.Select(x => x.Item1).Contains(cacheId)) + + if (!existentGuid.TryGetValue(cacheKey, out var cacheThingRevisionNumber)) { this.messageBus.SendObjectChangeEvent(thingObject, EventKind.Added); messageCounter++; } else { - var cacheThingRevisionNumber = existentGuid.Single(x => x.Item1.Equals(cacheId)).Item2; - if (dtoThing.RevisionNumber > cacheThingRevisionNumber) { // send event if revision number has increased from the old cached version @@ -243,7 +238,7 @@ public async Task Synchronize(IEnumerable dtoThings, bool } else if (dtoThing.RevisionNumber < cacheThingRevisionNumber) { - if (this.Cache.TryGetValue(cacheId, out var cacheThing)) + if (this.Cache.TryGetValue(cacheKey, out var cacheThing)) { // send event if revision number is lower. That means that the original cached item was changed (revision was added!) ICDPMessageBus.Current.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated); this.messageBus.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated); From 26c12bd93013678357d57f6608cd8c321bc2162f Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Fri, 22 Nov 2024 10:26:43 +0100 Subject: [PATCH 27/34] Revert "MessageBus performance" This reverts commit 1936e00af54a424ff03dc4e8f453a3f8a7b5c2ca. --- CDP4Dal/CDPMessageBus.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CDP4Dal/CDPMessageBus.cs b/CDP4Dal/CDPMessageBus.cs index ec19823df..61bd21072 100644 --- a/CDP4Dal/CDPMessageBus.cs +++ b/CDP4Dal/CDPMessageBus.cs @@ -57,7 +57,7 @@ public sealed class CDPMessageBus : ICDPMessageBus /// /// The holding the subscriptions. /// - private readonly ConcurrentDictionary messageBus = new ConcurrentDictionary(); + private readonly ConcurrentDictionary> messageBus = new ConcurrentDictionary>(); /// /// Number of currently active Observables in the @@ -124,7 +124,7 @@ private IObservable GetOrAddObservable(EventTypeTarget eventTypeTarget) { var cdpEventSubject = this.messageBus.GetOrAdd( eventTypeTarget, - this.ComposeEventSubject(eventTypeTarget)); + arg => new Lazy(() => this.ComposeEventSubject(eventTypeTarget))).Value; return (IObservable)cdpEventSubject.Observable; } @@ -201,7 +201,7 @@ public void SendMessage(T message, object target = null, string contract = nu if (getObservable) { - ((Subject)cdpEventSubject.Subject).OnNext(message); + ((Subject)cdpEventSubject.Value.Subject).OnNext(message); } } From d0e8bd9f46dd13bdaf0d17d1ba3ce2e7e2dd4b8d Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Mon, 25 Nov 2024 09:26:32 +0100 Subject: [PATCH 28/34] Review comments --- CDP4DalCommon/Protocol/Tasks/CometTask.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CDP4DalCommon/Protocol/Tasks/CometTask.cs b/CDP4DalCommon/Protocol/Tasks/CometTask.cs index f5615ed79..e25e78f49 100644 --- a/CDP4DalCommon/Protocol/Tasks/CometTask.cs +++ b/CDP4DalCommon/Protocol/Tasks/CometTask.cs @@ -71,7 +71,7 @@ public CometTask() /// /// A value of -1 is returned when the task is still running or not completed with success /// - public readonly int Duration => ComputeDuration(); + public readonly int Duration => this.ComputeDuration(); /// /// Gets or sets the at which the was started @@ -107,12 +107,12 @@ public CometTask() /// The computated duration private readonly int ComputeDuration() { - if (!FinishedAt.HasValue || !StartedAt.HasValue) + if (!this.FinishedAt.HasValue || !this.StartedAt.HasValue) { return -1; } - var timeSpan = FinishedAt.Value - StartedAt.Value; + var timeSpan = this.FinishedAt.Value - this.StartedAt.Value; return (int)timeSpan.TotalSeconds; } } From 53eb82349e6c6b40c066e0db6b81ba02138de413 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Tue, 26 Nov 2024 11:53:46 +0100 Subject: [PATCH 29/34] Move specific CDP4DalJsonSerializer project classes to CDP4JsonSerializer and remove CDP4DalJsonSerializer project --- CDP4-SDK.sln | 6 --- .../CDP4DalJsonSerializer.csproj | 44 ------------------- CDP4JsonFileDal/CDP4JsonFileDal.csproj | 1 - CDP4JsonFileDal/JsonFileDal.cs | 2 - CDP4JsonSerializer/CDP4JsonSerializer.csproj | 1 + .../Cdp4DalJsonSerializer.cs | 22 ++++------ .../Extensions/JsonElementExtensions.cs | 12 ++--- .../PostOperationJsonConverter.cs | 13 +++--- .../CDP4ServicesDal.NetCore.Tests.csproj | 1 - .../CdpServicesDalTestFixture.cs | 2 +- .../PostOperationTestFixture.cs | 2 +- .../CdpServicesDalTestFixture.cs | 2 +- .../PostOperationTestFixture.cs | 2 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 2 +- CDP4ServicesDal/CdpServicesDal.cs | 26 +++++------ .../PostOperationTestFixture.cs | 2 +- CDP4WspDal.Tests/PostOperationTestFixture.cs | 2 +- CDP4WspDal/CDP4WspDal.csproj | 2 +- CDP4WspDal/WSPDal.cs | 18 ++++---- 19 files changed, 52 insertions(+), 110 deletions(-) delete mode 100644 CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj rename {CDP4DalJsonSerializer => CDP4JsonSerializer}/Cdp4DalJsonSerializer.cs (80%) rename {CDP4DalJsonSerializer => CDP4JsonSerializer}/Extensions/JsonElementExtensions.cs (81%) rename {CDP4DalJsonSerializer => CDP4JsonSerializer}/JsonConverter/PostOperationJsonConverter.cs (92%) diff --git a/CDP4-SDK.sln b/CDP4-SDK.sln index 6a69cabc2..801dc90cc 100644 --- a/CDP4-SDK.sln +++ b/CDP4-SDK.sln @@ -78,8 +78,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4ServicesMessaging.Tests EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CDP4DalCommon", "CDP4DalCommon\CDP4DalCommon.csproj", "{E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CDP4DalJsonSerializer", "CDP4DalJsonSerializer\CDP4DalJsonSerializer.csproj", "{36C38A02-C1CF-4F4F-AB40-F0A231256B30}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -210,10 +208,6 @@ Global {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7CDB217-8442-4FD4-8E87-F4A8BFE9622A}.Release|Any CPU.Build.0 = Release|Any CPU - {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Debug|Any CPU.Build.0 = Debug|Any CPU - {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Release|Any CPU.ActiveCfg = Release|Any CPU - {36C38A02-C1CF-4F4F-AB40-F0A231256B30}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj b/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj deleted file mode 100644 index b24045f1d..000000000 --- a/CDP4DalJsonSerializer/CDP4DalJsonSerializer.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - net47;net471;net472;net48;netstandard2.0;netstandard2.1 - Starion Group S.A. - latest - CDP4DalJsonSerializer Community Edition - 28.0.0 - JsonSerializer for the CDP4DalCommon types - Copyright © Starion Group S.A. - Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime - CDP4DalJsonSerializer-CE - true - https://github.com/STARIONGROUP/COMET-SDK-Community-Edition - true - cdp4-icon.png - true - true - snupkg - https://github.com/STARIONGROUP/COMET-SDK-Community-Edition.git - CDP COMET ECSS-E-TM-10-25 - LGPL-3.0-only - - [Refactor] Newtonsoft to System.Text.Json - - README.md - true - latest - - - - \ - true - - - \ - true - - - - - - - diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 0f618bcad..5656ccdce 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -37,7 +37,6 @@ - diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index 608137755..dc1020d14 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -48,8 +48,6 @@ namespace CDP4JsonFileDal using CDP4DalCommon.Protocol.Operations; using CDP4DalCommon.Protocol.Tasks; - using CDP4DalJsonSerializer; - using CDP4JsonFileDal.Json; using CDP4JsonSerializer; diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index a95305638..739c5a4ef 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -44,6 +44,7 @@ + \ No newline at end of file diff --git a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4JsonSerializer/Cdp4DalJsonSerializer.cs similarity index 80% rename from CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs rename to CDP4JsonSerializer/Cdp4DalJsonSerializer.cs index 477449a51..2a5f15cee 100644 --- a/CDP4DalJsonSerializer/Cdp4DalJsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4DalJsonSerializer.cs @@ -22,26 +22,22 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalJsonSerializer +namespace CDP4JsonSerializer { using System; using CDP4Common.MetaInfo; - using CDP4DalCommon.Protocol.Operations; - - using CDP4DalJsonSerializer.JsonConverter; - - using CDP4JsonSerializer; + using CDP4JsonSerializer.JsonConverter; /// - /// The is a that also supports (de)serialization of - /// + /// The is a that also supports (de)serialization of + /// /// public class Cdp4DalJsonSerializer : Cdp4JsonSerializer { /// - /// Asserts that the have to be ignored + /// Asserts that the have to be ignored /// private readonly bool ignorePostOperationCopyProperty; @@ -54,7 +50,7 @@ public class Cdp4DalJsonSerializer : Cdp4JsonSerializer /// /// The supported version of the data-model /// - /// Asserts that the have to be ignored + /// Asserts that the have to be ignored public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty) { this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; @@ -62,16 +58,16 @@ public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version support } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Asserts that the have to be ignored + /// Asserts that the have to be ignored public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty) { this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; } /// - /// Initialize the property + /// Initialize the property /// public override void InitializeJsonSerializerOptions() { diff --git a/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs b/CDP4JsonSerializer/Extensions/JsonElementExtensions.cs similarity index 81% rename from CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs rename to CDP4JsonSerializer/Extensions/JsonElementExtensions.cs index c1a922b9b..d6bd679b1 100644 --- a/CDP4DalJsonSerializer/Extensions/JsonElementExtensions.cs +++ b/CDP4JsonSerializer/Extensions/JsonElementExtensions.cs @@ -22,7 +22,7 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalJsonSerializer.Extensions +namespace CDP4JsonSerializer.Extensions { using System.Collections.Generic; using System.Text.Json; @@ -34,16 +34,16 @@ namespace CDP4DalJsonSerializer.Extensions using CDP4DalCommon.Protocol.Operations; /// - /// Extension class for + /// Extension class for /// public static class JsonElementExtensions { /// - /// Deserialize the content of the to the + /// Deserialize the content of the to the /// - /// The - /// The that will receive new value properties - /// The + /// The + /// The that will receive new value properties + /// The public static void DeserializePostOperation(this JsonElement element, PostOperation postOperation, JsonSerializerOptions serializerOptions) { if (element.TryGetProperty("_delete", out var deleteElement)) diff --git a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs similarity index 92% rename from CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs rename to CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs index c391f0cb3..5cb462970 100644 --- a/CDP4DalJsonSerializer/JsonConverter/PostOperationJsonConverter.cs +++ b/CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -22,7 +22,7 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalJsonSerializer.JsonConverter +namespace CDP4JsonSerializer.JsonConverter { using System; using System.IO; @@ -31,15 +31,14 @@ namespace CDP4DalJsonSerializer.JsonConverter using System.Text.Json.Serialization; using CDP4Common.Polyfills; - using CDP4DalCommon.Protocol.Operations; - using CDP4DalJsonSerializer.Extensions; + using CDP4JsonSerializer.Extensions; using NLog; /// - /// The for s + /// The for s /// public class PostOperationJsonConverter: JsonConverter { @@ -49,14 +48,14 @@ public class PostOperationJsonConverter: JsonConverter private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// - /// Asserts that the have to be ignored + /// Asserts that the have to be ignored /// private readonly bool ignoreCopyProperty; /// /// Initializes a new instance. /// - /// Asserts that the have to be ignored + /// Asserts that the have to be ignored public PostOperationJsonConverter(bool ignoreCopyProperty) { this.ignoreCopyProperty = ignoreCopyProperty; @@ -76,7 +75,7 @@ public override bool CanConvert(Type typeToConvert) return typeof(PostOperation).QueryIsAssignableFrom(typeToConvert); } - /// Reads and converts the JSON to type . + /// Reads and converts the JSON to type . /// The reader. /// The type to convert. /// An object that specifies serialization options to use. diff --git a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj index 865cfab69..0f1670ea0 100644 --- a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj +++ b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj @@ -11,7 +11,6 @@ - diff --git a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs index 8edcbd97f..6a479f97e 100644 --- a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs @@ -849,7 +849,7 @@ public async Task VerifyWriteLongRunningTask() requestHandler.Respond(_ => thingsResponse); var stream = new MemoryStream(); - this.dal.Cdp4JsonSerializer.SerializeToStream(this.iteration, stream, true); + this.dal.Cdp4DalJsonSerializer.SerializeToStream(this.iteration, stream, true); stream.Position = 0; thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); diff --git a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs index c72c2ae40..ac195a939 100644 --- a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs @@ -39,7 +39,7 @@ namespace CDP4ServicesDal.Tests using CDP4DalCommon.Protocol.Operations; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using CDP4ServicesDal.Tests.Helper; diff --git a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs index 79a86cb22..bd1b5b864 100644 --- a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs @@ -883,7 +883,7 @@ public async Task VerifyWriteLongRunningTask() requestHandler.Respond(_ => thingsResponse); var stream = new MemoryStream(); - this.dal.Cdp4JsonSerializer.SerializeToStream(this.iteration, stream, true); + this.dal.Cdp4DalJsonSerializer.SerializeToStream(this.iteration, stream, true); stream.Position = 0; thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); diff --git a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs index 24d8bf43e..9c3f5d5e1 100644 --- a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs @@ -39,7 +39,7 @@ namespace CDP4ServicesDal.Tests using CDP4DalCommon.Protocol.Operations; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using CDP4ServicesDal.Tests.Helper; diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index f0387a207..a4915fd7d 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -42,8 +42,8 @@ - + diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index c8f1226dd..a12058806 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -54,7 +54,7 @@ namespace CDP4ServicesDal using CDP4DalCommon.Protocol.Operations; using CDP4DalCommon.Protocol.Tasks; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using CDP4MessagePackSerializer; @@ -108,7 +108,7 @@ public CdpServicesDal(): this(true) /// Asserts that the MessagePack deserialization should be used or not. Supported by default public CdpServicesDal(bool isMessagePackSupported) { - this.Cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); + this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); this.MessagePackSerializer = new MessagePackSerializer(); this.isMessagePackSupported = isMessagePackSupported; @@ -132,9 +132,9 @@ public CdpServicesDal(HttpClient httpClient, bool isMessagePackSupported = true) } /// - /// Gets the + /// Gets the /// - public Cdp4DalJsonSerializer Cdp4JsonSerializer { get; private set; } + public Cdp4DalJsonSerializer Cdp4DalJsonSerializer { get; private set; } /// /// Gets the @@ -225,7 +225,7 @@ public override async Task> Write(OperationContainer operatio { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - result.AddRange(this.Cdp4JsonSerializer.Deserialize(resultStream)); + result.AddRange(this.Cdp4DalJsonSerializer.Deserialize(resultStream)); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -517,7 +517,7 @@ public override async Task> Read(IEnumerable> Read(T thing, CancellationToke { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -746,7 +746,7 @@ public override async Task ReadCometTask(Guid id, CancellationToken c { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -807,7 +807,7 @@ public override async Task> ReadCometTasks(CancellationTo { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize>(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize>(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -951,7 +951,7 @@ public override async Task> Open(Credentials credentials, Can { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -1195,7 +1195,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op postOperation.ConstructFromOperation(operation); } - this.Cdp4JsonSerializer.SerializeToStream(postOperation, outputStream); + this.Cdp4DalJsonSerializer.SerializeToStream(postOperation, outputStream); outputStream.Position = 0; if (Logger.IsTraceEnabled) @@ -1425,8 +1425,8 @@ private LongRunningTaskResult ExtractResultFromStream(Stream stream) stream.Position = 0; return firstChar == '[' - ? new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)) - : new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)); + ? new LongRunningTaskResult(this.Cdp4DalJsonSerializer.Deserialize(stream)) + : new LongRunningTaskResult(this.Cdp4DalJsonSerializer.Deserialize(stream)); } } diff --git a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs index d97679516..06a7118f6 100644 --- a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs @@ -39,7 +39,7 @@ namespace CDP4WspDal.Tests using CDP4DalCommon.Protocol.Operations; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using CDP4WspDal.Tests.Helper; diff --git a/CDP4WspDal.Tests/PostOperationTestFixture.cs b/CDP4WspDal.Tests/PostOperationTestFixture.cs index d97679516..06a7118f6 100644 --- a/CDP4WspDal.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/PostOperationTestFixture.cs @@ -39,7 +39,7 @@ namespace CDP4WspDal.Tests using CDP4DalCommon.Protocol.Operations; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using CDP4WspDal.Tests.Helper; diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index 308604723..6de44c4e3 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -41,8 +41,8 @@ - + diff --git a/CDP4WspDal/WSPDal.cs b/CDP4WspDal/WSPDal.cs index 995f5714f..e704a89b4 100644 --- a/CDP4WspDal/WSPDal.cs +++ b/CDP4WspDal/WSPDal.cs @@ -52,7 +52,7 @@ namespace CDP4WspDal using CDP4DalCommon.Protocol.Operations; using CDP4DalCommon.Protocol.Tasks; - using CDP4DalJsonSerializer; + using CDP4JsonSerializer; using NLog; @@ -83,13 +83,13 @@ public class WspDal : Dal /// public WspDal() { - this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, true); + this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, true); } /// - /// Gets or sets the + /// Gets or sets the /// - public Cdp4DalJsonSerializer Serializer { get; private set; } + public Cdp4DalJsonSerializer Cdp4DalJsonSerializer { get; private set; } /// /// Gets the value indicating whether this is read only @@ -131,7 +131,7 @@ public override async Task> Write(OperationContainer operatio var watch = Stopwatch.StartNew(); - var hasCopyValuesOperations = operationContainer.Operations.Any(op => OperationKindExtensions.IsCopyKeepOriginalValuesOperation(op.OperationKind)); + var hasCopyValuesOperations = operationContainer.Operations.Any(op => op.OperationKind.IsCopyKeepOriginalValuesOperation()); var modifier = new OperationModifier(this.Session); var copyHandler = new CopyOperationHandler(this.Session); @@ -184,7 +184,7 @@ public override async Task> Write(OperationContainer operatio using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - result.AddRange(this.Serializer.Deserialize(resultStream)); + result.AddRange(this.Cdp4DalJsonSerializer.Deserialize(resultStream)); Guid iterationId; @@ -408,7 +408,7 @@ public override async Task> Read(T thing, CancellationToke using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - var returned = this.Serializer.Deserialize(resultStream); + var returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Guid iterationId; @@ -563,7 +563,7 @@ public override async Task> Open(Credentials credentials, Can using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - var returned = this.Serializer.Deserialize(resultStream); + var returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); watch.Stop(); Logger.Info("JSON Deserializer completed in {0} [ms]", watch.ElapsedMilliseconds); @@ -706,7 +706,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op postOperation.ConstructFromOperation(operation); } - this.Serializer.SerializeToStream(postOperation, outputStream); + this.Cdp4DalJsonSerializer.SerializeToStream(postOperation, outputStream); outputStream.Position = 0; if (Logger.IsTraceEnabled) From 64abba54d9a0a26c4a1c5fd49c2e5cadaad05d8b Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 27 Nov 2024 12:15:22 +0100 Subject: [PATCH 30/34] - use PostOperation where possible - Use same unit JsoinSerializer tests for Net and NetCore - Add extra datamodel version checks to JsonSerializers --- .../CDP4JsonSerializer.NetCore.Tests.csproj | 6 + .../CreateDerivedQuantityKindPostMessage.json | 62 ++++++++++ .../JsonSerializerPostOperationTestFixture.cs | 106 ++++++++++++++++++ ...ctorsOfDerivedQuantityKindPostMessage.json | 24 ++++ .../PostOperation/CdpPostOperation.cs | 50 --------- .../JsonSerializerPostOperationTestFixture.cs | 10 +- .../ActionItemSerializer.cs | 23 +++- .../ActualFiniteStateListSerializer.cs | 23 +++- .../ActualFiniteStateSerializer.cs | 23 +++- .../AutoGenDtoSerializer/AliasSerializer.cs | 23 +++- .../AndExpressionSerializer.cs | 23 +++- .../ApprovalSerializer.cs | 23 +++- .../ArrayParameterTypeSerializer.cs | 23 +++- .../BinaryNoteSerializer.cs | 23 +++- .../BinaryRelationshipRuleSerializer.cs | 23 +++- .../BinaryRelationshipSerializer.cs | 23 +++- .../AutoGenDtoSerializer/BookSerializer.cs | 23 +++- .../BooleanParameterTypeSerializer.cs | 23 +++- .../AutoGenDtoSerializer/BoundsSerializer.cs | 23 +++- .../BuiltInRuleVerificationSerializer.cs | 23 +++- .../CategorySerializer.cs | 23 +++- .../ChangeProposalSerializer.cs | 23 +++- .../ChangeRequestSerializer.cs | 23 +++- .../CitationSerializer.cs | 23 +++- .../AutoGenDtoSerializer/ColorSerializer.cs | 23 +++- .../CommonFileStoreSerializer.cs | 23 +++- .../CompoundParameterTypeSerializer.cs | 23 +++- .../ConstantSerializer.cs | 23 +++- .../ContractChangeNoticeSerializer.cs | 23 +++- .../CyclicRatioScaleSerializer.cs | 23 +++- .../DateParameterTypeSerializer.cs | 23 +++- .../DateTimeParameterTypeSerializer.cs | 23 +++- .../DecompositionRuleSerializer.cs | 23 +++- .../DefinitionSerializer.cs | 23 +++- ...endentParameterTypeAssignmentSerializer.cs | 23 +++- .../DerivedQuantityKindSerializer.cs | 23 +++- .../DerivedUnitSerializer.cs | 23 +++- .../DiagramCanvasSerializer.cs | 23 +++- .../DiagramEdgeSerializer.cs | 23 +++- .../DiagramObjectSerializer.cs | 23 +++- .../DomainFileStoreSerializer.cs | 23 +++- .../DomainOfExpertiseGroupSerializer.cs | 23 +++- .../DomainOfExpertiseSerializer.cs | 23 +++- .../ElementDefinitionSerializer.cs | 23 +++- .../ElementUsageSerializer.cs | 23 +++- .../EmailAddressSerializer.cs | 23 +++- ...eeringModelDataDiscussionItemSerializer.cs | 23 +++- .../EngineeringModelDataNoteSerializer.cs | 23 +++- .../EngineeringModelSerializer.cs | 23 +++- .../EngineeringModelSetupSerializer.cs | 23 +++- .../EnumerationParameterTypeSerializer.cs | 23 +++- .../EnumerationValueDefinitionSerializer.cs | 23 +++- .../ExclusiveOrExpressionSerializer.cs | 23 +++- .../ExternalIdentifierMapSerializer.cs | 23 +++- .../FileRevisionSerializer.cs | 23 +++- .../AutoGenDtoSerializer/FileSerializer.cs | 23 +++- .../FileTypeSerializer.cs | 23 +++- .../AutoGenDtoSerializer/FolderSerializer.cs | 23 +++- .../GlossarySerializer.cs | 23 +++- .../AutoGenDtoSerializer/GoalSerializer.cs | 23 +++- .../HyperLinkSerializer.cs | 23 +++- .../IdCorrespondenceSerializer.cs | 23 +++- ...endentParameterTypeAssignmentSerializer.cs | 23 +++- .../IntervalScaleSerializer.cs | 23 +++- .../IterationSerializer.cs | 23 +++- .../IterationSetupSerializer.cs | 23 +++- .../LinearConversionUnitSerializer.cs | 23 +++- .../LogEntryChangelogItemSerializer.cs | 23 +++- .../LogarithmicScaleSerializer.cs | 23 +++- .../MappingToReferenceScaleSerializer.cs | 23 +++- .../ModelLogEntrySerializer.cs | 23 +++- .../ModelReferenceDataLibrarySerializer.cs | 23 +++- .../ModellingThingReferenceSerializer.cs | 23 +++- .../MultiRelationshipRuleSerializer.cs | 23 +++- .../MultiRelationshipSerializer.cs | 23 +++- .../NaturalLanguageSerializer.cs | 23 +++- .../NestedElementSerializer.cs | 23 +++- .../NestedParameterSerializer.cs | 23 +++- .../NotExpressionSerializer.cs | 23 +++- .../AutoGenDtoSerializer/OptionSerializer.cs | 23 +++- .../OrExpressionSerializer.cs | 23 +++- .../OrdinalScaleSerializer.cs | 23 +++- .../OrganizationSerializer.cs | 23 +++- .../OrganizationalParticipantSerializer.cs | 23 +++- .../OwnedStyleSerializer.cs | 23 +++- .../AutoGenDtoSerializer/PageSerializer.cs | 23 +++- .../ParameterGroupSerializer.cs | 23 +++- .../ParameterOverrideSerializer.cs | 23 +++- .../ParameterOverrideValueSetSerializer.cs | 23 +++- .../ParameterSerializer.cs | 23 +++- .../ParameterSubscriptionSerializer.cs | 23 +++- ...ParameterSubscriptionValueSetSerializer.cs | 23 +++- .../ParameterTypeComponentSerializer.cs | 23 +++- .../ParameterValueSetSerializer.cs | 23 +++- .../ParameterizedCategoryRuleSerializer.cs | 23 +++- .../ParametricConstraintSerializer.cs | 23 +++- .../ParticipantPermissionSerializer.cs | 23 +++- .../ParticipantRoleSerializer.cs | 23 +++- .../ParticipantSerializer.cs | 23 +++- .../PersonPermissionSerializer.cs | 23 +++- .../PersonRoleSerializer.cs | 23 +++- .../AutoGenDtoSerializer/PersonSerializer.cs | 23 +++- .../AutoGenDtoSerializer/PointSerializer.cs | 23 +++- .../PossibleFiniteStateListSerializer.cs | 23 +++- .../PossibleFiniteStateSerializer.cs | 23 +++- .../PrefixedUnitSerializer.cs | 23 +++- .../PublicationSerializer.cs | 23 +++- .../QuantityKindFactorSerializer.cs | 23 +++- .../RatioScaleSerializer.cs | 23 +++- .../ReferenceSourceSerializer.cs | 23 +++- .../ReferencerRuleSerializer.cs | 23 +++- .../RelationalExpressionSerializer.cs | 23 +++- .../RelationshipParameterValueSerializer.cs | 23 +++- .../RequestForDeviationSerializer.cs | 23 +++- .../RequestForWaiverSerializer.cs | 23 +++- .../RequirementSerializer.cs | 23 +++- ...ementsContainerParameterValueSerializer.cs | 23 +++- .../RequirementsGroupSerializer.cs | 23 +++- .../RequirementsSpecificationSerializer.cs | 23 +++- .../ReviewItemDiscrepancySerializer.cs | 23 +++- .../RuleVerificationListSerializer.cs | 23 +++- .../RuleViolationSerializer.cs | 23 +++- .../SampledFunctionParameterTypeSerializer.cs | 23 +++- .../ScaleReferenceQuantityValueSerializer.cs | 23 +++- .../ScaleValueDefinitionSerializer.cs | 23 +++- .../AutoGenDtoSerializer/SectionSerializer.cs | 23 +++- .../SharedStyleSerializer.cs | 23 +++- .../SimpleParameterValueSerializer.cs | 23 +++- .../SimpleQuantityKindSerializer.cs | 23 +++- .../SimpleUnitSerializer.cs | 23 +++- .../SiteDirectoryDataAnnotationSerializer.cs | 23 +++- ...teDirectoryDataDiscussionItemSerializer.cs | 23 +++- .../SiteDirectorySerializer.cs | 23 +++- .../SiteDirectoryThingReferenceSerializer.cs | 23 +++- .../SiteLogEntrySerializer.cs | 23 +++- .../SiteReferenceDataLibrarySerializer.cs | 23 +++- .../SolutionSerializer.cs | 23 +++- .../SpecializedQuantityKindSerializer.cs | 23 +++- .../StakeHolderValueMapSerializer.cs | 23 +++- .../StakeHolderValueMapSettingsSerializer.cs | 23 +++- .../StakeholderSerializer.cs | 23 +++- .../StakeholderValueSerializer.cs | 23 +++- .../TelephoneNumberSerializer.cs | 23 +++- .../AutoGenDtoSerializer/TermSerializer.cs | 23 +++- .../TextParameterTypeSerializer.cs | 23 +++- .../TextualNoteSerializer.cs | 23 +++- .../TimeOfDayParameterTypeSerializer.cs | 23 +++- .../UnitFactorSerializer.cs | 23 +++- .../UnitPrefixSerializer.cs | 23 +++- .../UserPreferenceSerializer.cs | 23 +++- .../UserRuleVerificationSerializer.cs | 23 +++- .../ValueGroupSerializer.cs | 23 +++- CDP4JsonSerializer/CDP4JsonSerializer.csproj | 1 - 153 files changed, 3123 insertions(+), 494 deletions(-) create mode 100644 CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json create mode 100644 CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs create mode 100644 CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json delete mode 100644 CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs diff --git a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj index ceaef1877..f7de3a262 100644 --- a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj +++ b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj @@ -41,6 +41,12 @@ + + Always + + + Always + Always diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json b/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json new file mode 100644 index 000000000..11e51e3de --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json @@ -0,0 +1,62 @@ +{ + "_delete": [], + "_create": [ + { + "alias": [], + "category": [], + "classKind": "DerivedQuantityKind", + "defaultScale": "56863161-fa3a-47b8-a3cd-16465f734b27", + "definition": [], + "excludedDomain": [], + "excludedPerson": [], + "hyperLink": [], + "iid": "08c130ca-a270-408f-8069-b7e1d00659f0", + "isDeprecated": false, + "modifiedOn": "2018-08-12T14:10:55.560Z", + "name": "derivedQuantityKind", + "possibleScale": [ "56863161-fa3a-47b8-a3cd-16465f734b27" ], + "quantityDimensionSymbol": "dqk", + "quantityKindFactor": [ + { + "k": -12551680, + "v": "11aa4db6-40ef-4368-92ac-bda8af9b27a9" + }, + { + "k": 77606679, + "v": "125abfbd-f717-42c0-91da-738316159ea5" + } + ], + "revisionNumber": 0, + "shortName": "derivedQuantityKind", + "symbol": "derivedQuantityKind" + }, + { + "classKind": "QuantityKindFactor", + "excludedDomain": [], + "excludedPerson": [], + "exponent": "1", + "iid": "11aa4db6-40ef-4368-92ac-bda8af9b27a9", + "modifiedOn": "2018-08-12T14:10:45.476Z", + "quantityKind": "9513aca9-5397-48a1-8187-1683490bdb4f", + "revisionNumber": 0 + }, + { + "classKind": "QuantityKindFactor", + "excludedDomain": [], + "excludedPerson": [], + "exponent": "2", + "iid": "125abfbd-f717-42c0-91da-738316159ea5", + "modifiedOn": "2018-08-12T14:10:50.681Z", + "quantityKind": "1c53f8f4-024b-4f42-987a-439901a4bcb2", + "revisionNumber": 0 + } + ], + "_update": [ + { + "classKind": "SiteReferenceDataLibrary", + "iid": "bff9f871-3b7f-4e57-ac82-5ab499f9baf5", + "parameterType": [ "08c130ca-a270-408f-8069-b7e1d00659f0" ] + } + ], + "_copy": [] +} \ No newline at end of file diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs new file mode 100644 index 000000000..9833beaf3 --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs @@ -0,0 +1,106 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.NetCore.Tests.PostOperation +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Text; + + using CDP4Common.DTO; + using CDP4Common.MetaInfo; + using CDP4Common.Types; + + using CDP4DalCommon.Protocol.Operations; + + using NUnit.Framework; + + /// + /// Suite of tests to verify that PostOperation deserialization works as expected + /// + [TestFixture] + public class JsonSerializerPostOperationTestFixture + { + private IMetaDataProvider metaDataProvider; + + private Version supportedVersion; + + [SetUp] + public void SetUp() + { + this.metaDataProvider = new MetaDataProvider(); + this.supportedVersion = new Version(1,1,0); + } + + [Test] + public void Verify_that_post_message_with_move_keys_can_be_deserialized() + { + var postMessage = System.IO.File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json")); + var byteArray = Encoding.UTF8.GetBytes(postMessage); + var stream = new MemoryStream(byteArray); + + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); + + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + + Assert.That(cdpPostOperation.Create, Is.Empty); + Assert.That(cdpPostOperation.Delete, Is.Empty); + Assert.That(cdpPostOperation.Copy, Is.Empty); + + var classlessDto = cdpPostOperation.Update.First(); + + var orderedItems = classlessDto["QuantityKindFactor"] as IEnumerable; + + var orderedItem_1 = orderedItems.First(); + orderedItem_1.M = 77606679; + + var orderedItem_2 = orderedItems.Last(); + orderedItem_2.M = -12551680; + } + + [Test] + public void Verify_that_post_message_can_be_deserialized() + { + var postMessage = System.IO.File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "PostOperation/CreateDerivedQuantityKindPostMessage.json")); + var byteArray = Encoding.UTF8.GetBytes(postMessage); + var stream = new MemoryStream(byteArray); + + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); + + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + + Assert.That(cdpPostOperation.Delete, Is.Empty); + Assert.That(cdpPostOperation.Copy, Is.Empty); + + var derivedQuantityKind = cdpPostOperation.Create.First() as DerivedQuantityKind; + var qkf_1 = derivedQuantityKind.QuantityKindFactor.Single(x => x.K == -12551680); + + Assert.That(qkf_1.V, Is.Not.Null); + + Assert.That(qkf_1.M, Is.Null); + } + } +} \ No newline at end of file diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json b/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json new file mode 100644 index 000000000..5b7161c8f --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json @@ -0,0 +1,24 @@ +{ + "_delete": [], + "_create": [], + "_update": [ + { + "classKind": "DerivedQuantityKind", + "iid": "08c130ca-a270-408f-8069-b7e1d00659f0", + "modifiedOn": "2018-08-12T14:11:56.580Z", + "quantityKindFactor": [ + { + "k": -12551680, + "m": 77606679, + "v": "11aa4db6-40ef-4368-92ac-bda8af9b27a9" + }, + { + "k": 77606679, + "m": -12551680, + "v": "125abfbd-f717-42c0-91da-738316159ea5" + } + ] + } + ], + "_copy": [] +} \ No newline at end of file diff --git a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs b/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs deleted file mode 100644 index 15e11a1c8..000000000 --- a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-COMET SDK Community Edition -// -// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// ------------------------------------------------------------------------------------------------------------------------------- - -namespace CDP4JsonSerializer.Tests.Cdp4PostOperation -{ - using System.Collections.Generic; - using System.Text.Json.Serialization; - - using CDP4Common; - using CDP4Common.DTO; - - /// - /// A CdpPostOperation class used for testing purposes - /// - public class CdpPostOperation - { - [JsonPropertyName("_delete")] - public List Delete { get; set; } - - [JsonPropertyName("_create")] - public List Create { get; set; } - - [JsonPropertyName("_update")] - public List Update { get; set; } - - [JsonPropertyName("_copy")] - public List Copy { get; set; } - } -} diff --git a/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs b/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs index 8c654209f..96a623eac 100644 --- a/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs +++ b/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs @@ -34,7 +34,7 @@ namespace CDP4JsonSerializer.Tests.PostOperation using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer.Tests.Cdp4PostOperation; + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -62,9 +62,9 @@ public void Verify_that_post_message_with_move_keys_can_be_deserialized() var byteArray = Encoding.UTF8.GetBytes(postMessage); var stream = new MemoryStream(byteArray); - var cdp4JsonSerializer = new Cdp4JsonSerializer(this.metaDataProvider, this.supportedVersion); + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); - var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); Assert.That(cdpPostOperation.Create, Is.Empty); Assert.That(cdpPostOperation.Delete, Is.Empty); @@ -88,9 +88,9 @@ public void Verify_that_post_message_can_be_deserialized() var byteArray = Encoding.UTF8.GetBytes(postMessage); var stream = new MemoryStream(byteArray); - var cdp4JsonSerializer = new Cdp4JsonSerializer(this.metaDataProvider, this.supportedVersion); + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); - var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); Assert.That(cdpPostOperation.Delete, Is.Empty); Assert.That(cdpPostOperation.Copy, Is.Empty); diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index 5073e320a..adf25b96a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ActionItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index 97867f3c5..be6b270da 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ActualFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActualFiniteStateList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 8b016249e..456920b39 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActualFiniteState."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 47f8e6161..fcd77ae92 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class AliasSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Alias", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Alias."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 517095f1a..99a5d4989 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of AndExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 9acb8a5ee..00a6c5a3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ApprovalSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Approval", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Approval."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 2a92a61ce..ebfb29ed4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ArrayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ArrayParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 903b856bd..53960e843 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index 487e2d6cd..ebef7ecd8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BinaryRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryRelationshipRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index 6518815be..f438c50cd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryRelationship."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index 1d4fdeb0b..74f223206 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BookSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Book", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Book."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index b26f86244..5c50a5978 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BooleanParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BooleanParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index 6ee68c045..e2693e974 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BoundsSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Bounds."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index ea17a9ada..fe05b68a0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BuiltInRuleVerification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index e159430a3..cc55acb33 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class CategorySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Category", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Category."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index e54c961e7..1ce320507 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ChangeProposalSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ChangeProposal."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index 308bc002c..a6f60e1fc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ChangeRequestSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ChangeRequest."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index 40af0fdb1..9c255fc30 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class CitationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Citation", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Citation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 0fe2f658b..a30ee38eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ColorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Color", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Color."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 7104c4942..6bd8f03fb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CommonFileStore."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index 7f3dbc595..a21a5318c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class CompoundParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CompoundParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index b4425495f..66e881da0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ConstantSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Constant", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Constant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 6cb9fd11a..1c39b5553 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ContractChangeNoticeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ContractChangeNotice."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index ce4d2cb94..45824187c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class CyclicRatioScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CyclicRatioScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 760e45790..4310262d9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DateParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DateParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index 6a4f2e03e..382ccc97b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DateTimeParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DateTimeParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index 15c70da75..e0c22aaf4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DecompositionRuleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DecompositionRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index ca8058d46..fadd0fa6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DefinitionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Definition", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Definition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 8e595bd50..4e97b8ed9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.2.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DependentParameterTypeAssignment."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index 34f843a9e..059c6ed9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DerivedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DerivedQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index 5b1d7f0c1..c112d9b7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DerivedUnitSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DerivedUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index a6cd44377..917889ad2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramCanvas."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 895eb57d2..8e4d6061f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DiagramEdgeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramEdge."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 8143e6a82..2f0ef799f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DiagramObjectSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramObject."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index 5f81ab4f7..5f19382a0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainFileStore."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index c9667147f..b74c9795a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DomainOfExpertiseGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainOfExpertiseGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index c41b9dbc3..599285a67 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class DomainOfExpertiseSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainOfExpertise."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index b6961ed99..f59e87469 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ElementDefinitionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ElementDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 94f472574..7051b9913 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ElementUsageSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ElementUsage."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index bd1163b07..f246bea4d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EmailAddress."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index b7a0eb433..f11e6531a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelDataDiscussionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 154c5b0c1..82da9c1a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelDataNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 5acc4b77f..51c02e39a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EngineeringModelSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModel."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index c25f19b4b..b2744c810 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EngineeringModelSetupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelSetup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 7f530a8b7..baa824208 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EnumerationParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EnumerationParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 4c23cbca8..d378b0aae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class EnumerationValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EnumerationValueDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index d9d3732ab..3bb4ce09a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ExclusiveOrExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 6ffeb5fc0..c267b5b5e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ExternalIdentifierMap."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index 5c6333c05..d923a98bf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of FileRevision."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 4e77b2aad..bdcdec3eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class FileSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a File", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of File."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 91c6feffa..6e7a0c35f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class FileTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a FileType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of FileType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 7ad26feb4..9adee42ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class FolderSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Folder", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Folder."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index 356b31da8..94db94404 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class GlossarySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Glossary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 5c0edcb97..75cd0cc56 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class GoalSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Goal", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Goal."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 7b306e4ba..12ec0a0ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of HyperLink."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index cda931b33..facb617b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IdCorrespondence."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index cd10954ea..009036c37 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.2.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IndependentParameterTypeAssignment."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index b3747c45e..f342628ad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class IntervalScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IntervalScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index fc4e243df..04e48b1dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class IterationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Iteration."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index 94659870e..dd1b513e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class IterationSetupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IterationSetup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 7a02a38ea..9316266a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class LinearConversionUnitSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LinearConversionUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index e7cef7530..aef472fe9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.2.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LogEntryChangelogItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index 5c04086d2..1576215be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class LogarithmicScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LogarithmicScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index 8aaddf4f7..43f6de80b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MappingToReferenceScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index e16d5dd13..05cc1c703 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ModelLogEntrySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModelLogEntry."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 5090210aa..e0c3ae6e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ModelReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModelReferenceDataLibrary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 638d266a4..cd8d424a4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModellingThingReference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index d521b762d..8cf6cca31 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class MultiRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MultiRelationshipRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 732b37b4c..c3900ad34 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MultiRelationship."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index 97c4f8f18..65c9c7b5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NaturalLanguage."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 700477336..84fd12866 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class NestedElementSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NestedElement."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index c4ba39bb4..bc44d710e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NestedParameter."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index ea3fb15eb..02753f1f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NotExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 462a94291..e7ccabf15 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OptionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Option", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Option."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index c53f2c030..b3d2f6768 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 14c6f5b02..e45f32f7d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OrdinalScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrdinalScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 2111dc5a6..03e301618 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OrganizationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Organization", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Organization."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 4cec229c8..41882f887 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.2.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrganizationalParticipant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 1c4c03ca2..97065e4ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class OwnedStyleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OwnedStyle."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index d537ba163..0145b989b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PageSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Page", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Page."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index aef6bc3f7..1b5766f96 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 1aaeb7a16..bd885dd9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterOverride."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index 3de5898cf..6df67a5b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterOverrideValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index e0f315673..745cd888d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Parameter."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 1f6f3b9f2..31843c6c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterSubscription."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index 01180b858..702f1096c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterSubscriptionValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index cf56b41e4..af143ec3c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterTypeComponent."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index 4f9a06cca..bdf128dfa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterValueSetSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index 8eb7102a9..ff1f730c2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParameterizedCategoryRuleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterizedCategoryRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 0a34725d8..c9f9a5616 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParametricConstraintSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParametricConstraint."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index 83c426295..8ae023350 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParticipantPermission."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index f3eca8f1e..20c6912cf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParticipantRoleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParticipantRole."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index dc27bc41e..e6a1ac2c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ParticipantSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Participant", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Participant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index 0de2a6cc1..d9e5e85b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PersonPermission."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 627d79e01..9f95cfae6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PersonRoleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PersonRole."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index 24d9f7b85..d442f541b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PersonSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Person", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Person."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index 8e0a4f390..b5fa7ed99 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PointSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Point", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Point."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 7c5b1aa45..b37eb8983 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PossibleFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PossibleFiniteStateList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index cb8f53322..a420eaaa3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PossibleFiniteStateSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PossibleFiniteState."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index dfd6323e3..68d70bb57 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PrefixedUnitSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PrefixedUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index b3ba81a33..10c69f263 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class PublicationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Publication", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Publication."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 113010aec..2a15e45d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of QuantityKindFactor."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index 169695b8a..2b09acc5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RatioScaleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RatioScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index 421178168..29ed4961f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ReferenceSourceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReferenceSource."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index a11d1a27f..cc796d870 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ReferencerRuleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReferencerRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index 3c0e5e4f4..091764438 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RelationalExpressionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RelationalExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index cdb206dde..98d7b841b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RelationshipParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 099c10c3e..7ea791a3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequestForDeviationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequestForDeviation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index a78bc243e..129663b11 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequestForWaiverSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequestForWaiver."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index 30c9ab01b..2b8c1a8e0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequirementSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Requirement."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index 56b76c3a6..cb5df63b2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequirementsContainerParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsContainerParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index d4581e74d..f32a253ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequirementsGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index ca7ec651d..62cf715f3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RequirementsSpecificationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsSpecification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index 9f2eb119b..12711c378 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ReviewItemDiscrepancySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReviewItemDiscrepancy."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index edc4da66a..fba32f31b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RuleVerificationListSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RuleVerificationList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index 88351483d..a598e3763 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RuleViolation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index b28caf532..2e08bba00 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.2.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SampledFunctionParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index 07f15a290..2cc11f6a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ScaleReferenceQuantityValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index 73f923029..dd161dafb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ScaleValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ScaleValueDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 6b927fe51..2037b6b5b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SectionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Section", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Section."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index e143670a2..ee765f6d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SharedStyleSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SharedStyle."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 2bbac1977..116186b66 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index 55a0dc9bf..d5da8cfc2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SimpleQuantityKindSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index f38ff1df9..33fc3b205 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SimpleUnitSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 10fdeb21c..f725f429b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryDataAnnotation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index 712ba3443..abe659e53 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryDataDiscussionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index 882e37d3f..a8e87fb3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteDirectorySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectory."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 9cbdbe6a3..7a6992584 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryThingReference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 1b4bec2ef..3bea41e37 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteLogEntrySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteLogEntry."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index c0ebc3cec..a2f153e66 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SiteReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteReferenceDataLibrary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index 2e9e8cca7..211260c1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SolutionSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Solution", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Solution."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index b5862170f..3a100859b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class SpecializedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SpecializedQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index da44522c3..a129ffbc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class StakeHolderValueMapSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeHolderValueMap."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 234b07918..2210e26f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class StakeHolderValueMapSettingsSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeHolderValueMapSettings."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index c3c201067..906ba8d0d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class StakeholderSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Stakeholder."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 3a1feeee1..87a1b966a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeholderValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index 4aade4864..099bba9d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TelephoneNumber."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 42e15fc06..8211cb823 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class TermSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a Term", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Term."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index a19cafc60..7d47a3e64 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class TextParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TextParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index aa7032dc6..78f665b94 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TextualNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index 2af70a333..c66f62fe3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class TimeOfDayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TimeOfDayParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index 4d93a402c..63ae81ea9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UnitFactor."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 0b840ce1a..5a48c7584 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class UnitPrefixSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UnitPrefix."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 74bfe286c..600843cfa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UserPreference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index 45b9ab8c0..78fbfa20b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.0.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UserRuleVerification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); return; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 57507be25..24dfcbd78 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -1,5 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. // // Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar @@ -50,6 +49,19 @@ namespace CDP4JsonSerializer /// public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer { + /// + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + /// /// Serializes a into an /// @@ -65,7 +77,12 @@ public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataM throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); } - if (requestedDataModelVersion < Version.Parse("1.1.0")) + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ValueGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) { Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); return; diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index 739c5a4ef..02ac76dde 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -28,7 +28,6 @@ - From e4da0afedcd4340e9a0d71a0641825fd3a957c70 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 27 Nov 2024 13:52:32 +0100 Subject: [PATCH 31/34] - use Microsoft.AspNet.WebApi.Client instead of System.Net.Http.Formatting.Extension --- CDP4ServicesDal/CDP4ServicesDal.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index a4915fd7d..f1c76fb64 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -27,7 +27,7 @@ - + From 202226821360774434f01ae24651e1dfd6996131 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Wed, 27 Nov 2024 15:16:47 +0100 Subject: [PATCH 32/34] - Refactor creation of default JsonSerializerOptions --- CDP4JsonSerializer/Cdp4JsonSerializer.cs | 4 +- .../Helper/JsonSerializerOptionsCreator.cs | 49 +++++++++++ CDP4JsonSerializer/Helper/SerializerHelper.cs | 25 +++++- CDP4JsonSerializer/SerializerOptions.cs | 88 ------------------- 4 files changed, 73 insertions(+), 93 deletions(-) create mode 100644 CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs delete mode 100644 CDP4JsonSerializer/SerializerOptions.cs diff --git a/CDP4JsonSerializer/Cdp4JsonSerializer.cs b/CDP4JsonSerializer/Cdp4JsonSerializer.cs index 49aafe452..91b2f10d1 100644 --- a/CDP4JsonSerializer/Cdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4JsonSerializer.cs @@ -33,6 +33,7 @@ namespace CDP4JsonSerializer using CDP4Common.MetaInfo; + using CDP4JsonSerializer.Helper; using CDP4JsonSerializer.JsonConverter; using NLog; @@ -320,7 +321,8 @@ public T Deserialize(string contentString) /// public virtual void InitializeJsonSerializerOptions() { - this.JsonSerializerOptions = SerializerOptions.Copy(); + this.JsonSerializerOptions = JsonSerializerOptionsCreator.CreateNew(); + this.JsonSerializerOptions.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); this.JsonSerializerOptions.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false)); diff --git a/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs b/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs new file mode 100644 index 000000000..8ed2b7e9b --- /dev/null +++ b/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs @@ -0,0 +1,49 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.Helper +{ + using System.Text.Json; + + /// + /// Static class that returns correct for serialization purposes + /// + public static class JsonSerializerOptionsCreator + { + /// + /// Creates the and returns the new instance + /// + /// the new instance + public static JsonSerializerOptions CreateNew() + { + return new JsonSerializerOptions + { + WriteIndented = false, + Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + PropertyNameCaseInsensitive = true, + NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString, + }; + } + } +} diff --git a/CDP4JsonSerializer/Helper/SerializerHelper.cs b/CDP4JsonSerializer/Helper/SerializerHelper.cs index 5e34f6dec..50925b2d5 100644 --- a/CDP4JsonSerializer/Helper/SerializerHelper.cs +++ b/CDP4JsonSerializer/Helper/SerializerHelper.cs @@ -1,6 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // @@ -32,6 +32,8 @@ namespace CDP4JsonSerializer using CDP4Common.Types; + using CDP4JsonSerializer.Helper; + /// /// Utility method to convert a JSON token to a CDP4 type /// @@ -42,15 +44,30 @@ public static class SerializerHelper /// public const string DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffZ"; + /// + /// The default instance for this class + /// + private static readonly JsonSerializerOptions JsonSerializerOptions; + /// /// Regex used for conversion of Json value to string /// - private static readonly Regex JsonToValueArrayRegex = new(@"^\[(.*)\]$", RegexOptions.Singleline); + private static readonly Regex JsonToValueArrayRegex ; /// /// Regex used for conversion of HStore value to string /// - private static readonly Regex HstoreToValueArrayRegex = new(@"^\{(.*)\}$", RegexOptions.Singleline); + private static readonly Regex HstoreToValueArrayRegex; + + /// + /// Creates the new instance of the static class + /// + static SerializerHelper() + { + JsonSerializerOptions = JsonSerializerOptionsCreator.CreateNew(); + JsonToValueArrayRegex = new(@"^\[(.*)\]$", RegexOptions.Singleline); + HstoreToValueArrayRegex = new(@"^\{(.*)\}$", RegexOptions.Singleline); + } /// /// Convert a string to a @@ -227,7 +244,7 @@ private static IEnumerable ValueArrayToStringList(ValueArray val for (var i = 0; i < items.Count; i++) { - items[i] = $"{JsonSerializer.Serialize(items[i], SerializerOptions.Options)}"; + items[i] = $"{JsonSerializer.Serialize(items[i], JsonSerializerOptions)}"; } return items; diff --git a/CDP4JsonSerializer/SerializerOptions.cs b/CDP4JsonSerializer/SerializerOptions.cs deleted file mode 100644 index 4f4642708..000000000 --- a/CDP4JsonSerializer/SerializerOptions.cs +++ /dev/null @@ -1,88 +0,0 @@ -// ------------------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar -// -// This file is part of CDP4-COMET SDK Community Edition -// -// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// ------------------------------------------------------------------------------------------------------------------------------- - -namespace CDP4JsonSerializer -{ - using System.Text.Json; - - /// - /// Static class with the options used in the serializer - /// - public class SerializerOptions - { - /// - /// Backing field for the property - /// - private static JsonSerializerOptions options; - - /// - /// Object to lock the options - /// - private static readonly object Lock = new(); - - /// - /// Creates a new instance of type - /// - private SerializerOptions() - { - } - - /// - /// Gets the instance that it's been used of this - /// - public static JsonSerializerOptions Options - { - get - { - if (options == null) - { - lock (Lock) - { - if (options == null) - { - options = new JsonSerializerOptions() - { - WriteIndented = false, - Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - PropertyNameCaseInsensitive = true, - NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString - }; - } - } - } - - return options; - } - } - - /// - /// Copies the and returns a new instance - /// - /// the new instance - public static JsonSerializerOptions Copy() - { - return new JsonSerializerOptions(Options); - } - } -} From a1f429a21e0796dcea504dc8f7cdfb93ac887c32 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Fri, 29 Nov 2024 14:26:26 +0100 Subject: [PATCH 33/34] Review comment --- CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs index f7422d122..bd03a4487 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs @@ -1,17 +1,17 @@ // -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// +// // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Jaime Bernar // -// This file is part of CDP4-SDK Community Edition +// This file is part of CDP4-COMET-SDK Community Edition // -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// The CDP4-COMET-SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. From 73b763eea92e377b1e420cd7599719bbe9c95814 Mon Sep 17 00:00:00 2001 From: Alexander van Delft Date: Mon, 2 Dec 2024 14:09:57 +0100 Subject: [PATCH 34/34] Always support MessagePack deserialization as a DefaultRequestHeader and fix unit tests accordingly --- .../CdpServicesDalTestFixture.cs | 7 ++-- .../CdpServicesDalTestFixture.cs | 7 ++-- CDP4ServicesDal/CdpServicesDal.cs | 34 +++---------------- 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs index 6a479f97e..515f73e50 100644 --- a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs @@ -255,12 +255,11 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed() Assert.Throws(() => this.dal.Close()); } - [TestCase(true)] - [TestCase(false)] + [Test] [Category("WebServicesDependent")] - public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported) + public async Task VerifyThatReadReturnsCorrectDTO() { - this.dal = new CdpServicesDal(isMessagePackSupported); + this.dal = new CdpServicesDal(); var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList(); Assert.That(returned, Is.Not.Null); diff --git a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs index bd1b5b864..6add04da1 100644 --- a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs @@ -232,12 +232,11 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed() Assert.Throws(() => this.dal.Close()); } - [TestCase(true)] - [TestCase(false)] + [Test] [Category("WebServicesDependent")] - public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported) + public async Task VerifyThatReadReturnsCorrectDTO() { - this.dal = new CdpServicesDal(isMessagePackSupported); + this.dal = new CdpServicesDal(); var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList(); Assert.That(returned, Is.Not.Null); diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index a12058806..1b994f883 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -89,29 +89,13 @@ public class CdpServicesDal : Dal /// private HttpClient httpClient; - /// - /// Asserts that the MessagePack deserialization should be used or not - /// - private readonly bool isMessagePackSupported; - - /// - /// Initializes a new instance of the class. - /// - public CdpServicesDal(): this(true) - { - // Default constructor - } - /// /// Initializes a new instance of the class. /// - /// Asserts that the MessagePack deserialization should be used or not. Supported by default - public CdpServicesDal(bool isMessagePackSupported) + public CdpServicesDal() { this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); this.MessagePackSerializer = new MessagePackSerializer(); - - this.isMessagePackSupported = isMessagePackSupported; } /// @@ -120,15 +104,9 @@ public CdpServicesDal(bool isMessagePackSupported) /// /// The (injected) /// - /// Asserts that the MessagePack deserialization should be used or not. Supported by default - public CdpServicesDal(HttpClient httpClient, bool isMessagePackSupported = true) : this(isMessagePackSupported) + public CdpServicesDal(HttpClient httpClient) : this() { - if (httpClient == null) - { - throw new ArgumentNullException(nameof(httpClient)); - } - - this.httpClient = httpClient; + this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); } /// @@ -1106,11 +1084,7 @@ private HttpClient CreateHttpClient(Credentials credentials, HttpClient injected result.BaseAddress = credentials.Uri; result.DefaultRequestHeaders.Accept.Clear(); result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - - if (this.isMessagePackSupported) - { - result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack")); - } + result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack")); result.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{credentials.UserName}:{credentials.Password}"))); result.DefaultRequestHeaders.Add(Headers.AcceptCdpVersion, Headers.AcceptCdpVersionValue);